Skip to content

Commit 680c64d

Browse files
Shawnshhlijinxia
authored andcommitted
HV:transfer vmid's type to uint16_t
vmid's type prefered to be uint16_t. V1->V2:vmid from uint32_t transfer to uint16_t V2->V3:add range check to hcall's vmid parameter V3->V4:seperate the declaration and actual code. V4->V5:remove range check from hcall's vmid parameter Signed-off-by: Huihuang Shi <huihuang.shi@intel.com> Acked-by: Eddie Dong <eddie.dong@intel.com>
1 parent 6ad1508 commit 680c64d

File tree

13 files changed

+57
-35
lines changed

13 files changed

+57
-35
lines changed

hypervisor/arch/x86/guest/vioapic.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -651,7 +651,7 @@ bool vioapic_get_rte(struct vm *vm, uint8_t pin, void *rte)
651651
}
652652

653653
#ifdef HV_DEBUG
654-
void get_vioapic_info(char *str, int str_max, int vmid)
654+
void get_vioapic_info(char *str, int str_max, uint16_t vmid)
655655
{
656656
int len, size = str_max, delmode;
657657
uint64_t rte;
@@ -662,7 +662,7 @@ void get_vioapic_info(char *str, int str_max, int vmid)
662662

663663
if (vm == NULL) {
664664
len = snprintf(str, size,
665-
"\r\nvm is not exist for vmid %d", vmid);
665+
"\r\nvm is not exist for vmid %hu", vmid);
666666
size -= len;
667667
str += len;
668668
goto END;

hypervisor/arch/x86/guest/vm.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ static void init_vm(struct vm_description *vm_desc,
4242
/* return a pointer to the virtual machine structure associated with
4343
* this VM ID
4444
*/
45-
struct vm *get_vm_from_vmid(int vm_id)
45+
struct vm *get_vm_from_vmid(uint16_t vm_id)
4646
{
4747
struct vm *vm = NULL;
4848
struct list_head *pos;

hypervisor/arch/x86/trusty.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ static void create_secure_world_ept(struct vm *vm, uint64_t gpa_orig,
8686
IA32E_EPT_X_BIT);
8787
uint64_t pdpte = 0, *dest_pdpte_p = NULL, *src_pdpte_p = NULL;
8888
void *sub_table_addr = NULL, *pml4_base = NULL;
89-
struct vm *vm0 = get_vm_from_vmid(0);
89+
struct vm *vm0 = get_vm_from_vmid(0U);
9090
uint16_t i;
9191
struct vcpu *vcpu;
9292

@@ -186,7 +186,7 @@ static void create_secure_world_ept(struct vm *vm, uint64_t gpa_orig,
186186
void destroy_secure_world(struct vm *vm)
187187
{
188188
struct map_params map_params;
189-
struct vm *vm0 = get_vm_from_vmid(0);
189+
struct vm *vm0 = get_vm_from_vmid(0U);
190190

191191
if (vm0 == NULL) {
192192
pr_err("Parse vm0 context failed.");

hypervisor/arch/x86/vtd.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ struct iommu_domain {
147147
bool is_host;
148148
bool is_tt_ept; /* if reuse EPT of the domain */
149149
uint16_t dom_id;
150-
int vm_id;
150+
uint16_t vm_id;
151151
uint32_t addr_width; /* address width of the domain */
152152
uint64_t trans_table_ptr;
153153
};
@@ -862,7 +862,7 @@ static void dmar_disable(struct dmar_drhd_rt *dmar_uint)
862862
dmar_fault_event_mask(dmar_uint);
863863
}
864864

865-
struct iommu_domain *create_iommu_domain(int vm_id, uint64_t translation_table,
865+
struct iommu_domain *create_iommu_domain(uint16_t vm_id, uint64_t translation_table,
866866
int addr_width)
867867
{
868868
struct iommu_domain *domain;
@@ -896,7 +896,7 @@ struct iommu_domain *create_iommu_domain(int vm_id, uint64_t translation_table,
896896
list_add(&domain->list, &iommu_domains);
897897
spinlock_release(&domain_lock);
898898

899-
dev_dbg(ACRN_DBG_IOMMU, "create domain [%d]: vm_id = %d, ept@0x%x",
899+
dev_dbg(ACRN_DBG_IOMMU, "create domain [%d]: vm_id = %hu, ept@0x%x",
900900
domain->dom_id,
901901
domain->vm_id,
902902
domain->trans_table_ptr);

hypervisor/common/hypercall.c

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ handle_vioapic_irqline(struct vm *vm, int irq, enum irq_mode mode)
9393
return ret;
9494
}
9595

96-
static int handle_virt_irqline(struct vm *vm, uint64_t target_vmid,
96+
static int handle_virt_irqline(struct vm *vm, uint16_t target_vmid,
9797
struct acrn_irqline *param, enum irq_mode mode)
9898
{
9999
int32_t ret = 0;
@@ -218,7 +218,6 @@ int64_t hcall_create_vcpu(struct vm *vm, uint64_t vmid, uint64_t param)
218218
int32_t ret;
219219
uint16_t pcpu_id;
220220
struct acrn_create_vcpu cv;
221-
222221
struct vm *target_vm = get_vm_from_vmid(vmid);
223222

224223
if ((target_vm == NULL) || (param == 0U)) {
@@ -250,7 +249,7 @@ int64_t hcall_assert_irqline(struct vm *vm, uint64_t vmid, uint64_t param)
250249
pr_err("%s: Unable copy param to vm\n", __func__);
251250
return -1;
252251
}
253-
ret = handle_virt_irqline(vm, vmid, &irqline, IRQ_ASSERT);
252+
ret = handle_virt_irqline(vm, (uint16_t)vmid, &irqline, IRQ_ASSERT);
254253

255254
return ret;
256255
}
@@ -264,7 +263,7 @@ int64_t hcall_deassert_irqline(struct vm *vm, uint64_t vmid, uint64_t param)
264263
pr_err("%s: Unable copy param to vm\n", __func__);
265264
return -1;
266265
}
267-
ret = handle_virt_irqline(vm, vmid, &irqline, IRQ_DEASSERT);
266+
ret = handle_virt_irqline(vm, (uint16_t)vmid, &irqline, IRQ_DEASSERT);
268267

269268
return ret;
270269
}
@@ -278,7 +277,7 @@ int64_t hcall_pulse_irqline(struct vm *vm, uint64_t vmid, uint64_t param)
278277
pr_err("%s: Unable copy param to vm\n", __func__);
279278
return -1;
280279
}
281-
ret = handle_virt_irqline(vm, vmid, &irqline, IRQ_PULSE);
280+
ret = handle_virt_irqline(vm, (uint16_t)vmid, &irqline, IRQ_PULSE);
282281

283282
return ret;
284283
}
@@ -741,7 +740,7 @@ int64_t hcall_setup_sbuf(struct vm *vm, uint64_t param)
741740

742741
int64_t hcall_get_cpu_pm_state(struct vm *vm, uint64_t cmd, uint64_t param)
743742
{
744-
int32_t target_vm_id;
743+
uint16_t target_vm_id;
745744
struct vm *target_vm;
746745

747746
target_vm_id = (cmd & PMCMD_VMID_MASK) >> PMCMD_VMID_SHIFT;

hypervisor/common/io_request.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ static void fire_vhm_interrupt(void)
1616
struct vm *vm0;
1717
struct vcpu *vcpu;
1818

19-
vm0 = get_vm_from_vmid(0);
19+
vm0 = get_vm_from_vmid(0U);
2020
ASSERT(vm0 != NULL, "VM Pointer is NULL");
2121

2222
vcpu = vcpu_from_vid(vm0, 0);

hypervisor/debug/shell_internal.c

Lines changed: 35 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -549,7 +549,7 @@ int shell_pause_vcpu(struct shell *p_shell,
549549
int argc, char **argv)
550550
{
551551
int status = 0;
552-
uint32_t vm_id;
552+
uint16_t vm_id;
553553
uint16_t vcpu_id;
554554
struct vm *vm;
555555
struct vcpu *vcpu;
@@ -560,7 +560,12 @@ int shell_pause_vcpu(struct shell *p_shell,
560560
shell_puts(p_shell,
561561
"Please enter correct cmd with <vm_id, vcpu_id>\r\n");
562562
} else {
563-
vm_id = atoi(argv[1]);
563+
status = atoi(argv[1]);
564+
if (status < 0) {
565+
return -EINVAL;
566+
} else {
567+
vm_id = (uint16_t)status;
568+
}
564569
vcpu_id = (uint16_t)atoi(argv[2]);
565570
if (vcpu_id >= phys_cpu_num)
566571
return (-EINVAL);
@@ -600,7 +605,7 @@ int shell_resume_vcpu(struct shell *p_shell,
600605
int argc, char **argv)
601606
{
602607
int status = 0;
603-
uint32_t vm_id;
608+
uint16_t vm_id;
604609
uint16_t vcpu_id;
605610
struct vm *vm;
606611
struct vcpu *vcpu;
@@ -611,7 +616,11 @@ int shell_resume_vcpu(struct shell *p_shell,
611616
shell_puts(p_shell,
612617
"Please enter correct cmd with <vm_id, vcpu_id>\r\n");
613618
} else {
614-
vm_id = atoi(argv[1]);
619+
status = atoi(argv[1]);
620+
if (status < 0) {
621+
return -EINVAL;
622+
}
623+
vm_id = (uint16_t)status;
615624
vcpu_id = (uint16_t)atoi(argv[2]);
616625
if (vcpu_id >= phys_cpu_num)
617626
return (-EINVAL);
@@ -650,7 +659,7 @@ int shell_vcpu_dumpreg(struct shell *p_shell,
650659
int argc, char **argv)
651660
{
652661
int status = 0;
653-
uint32_t vm_id;
662+
uint16_t vm_id;
654663
uint16_t vcpu_id;
655664
char temp_str[MAX_STR_SIZE];
656665
struct vm *vm;
@@ -667,7 +676,11 @@ int shell_vcpu_dumpreg(struct shell *p_shell,
667676
return -EINVAL;
668677
}
669678

670-
vm_id = atoi(argv[1]);
679+
status = atoi(argv[1]);
680+
if (status < 0) {
681+
return -EINVAL;
682+
}
683+
vm_id = (uint16_t)status;
671684
vcpu_id = (uint16_t)atoi(argv[2]);
672685
if (vcpu_id >= phys_cpu_num)
673686
return (-EINVAL);
@@ -743,7 +756,7 @@ int shell_vcpu_dumpreg(struct shell *p_shell,
743756
shell_puts(p_shell, "Cannot handle user gva yet!\r\n");
744757
} else {
745758
snprintf(temp_str, MAX_STR_SIZE,
746-
"\r\nDump RSP for vm %d, from "
759+
"\r\nDump RSP for vm %hu, from "
747760
"gva 0x%016llx\r\n",
748761
vm_id, cur_context->rsp);
749762
shell_puts(p_shell, temp_str);
@@ -766,7 +779,7 @@ int shell_vcpu_dumpmem(struct shell *p_shell,
766779
int argc, char **argv)
767780
{
768781
int status = 0;
769-
uint32_t vm_id;
782+
uint16_t vm_id;
770783
uint16_t vcpu_id;
771784
uint64_t gva;
772785
uint64_t tmp[MAX_MEMDUMP_LEN/8];
@@ -785,7 +798,11 @@ int shell_vcpu_dumpmem(struct shell *p_shell,
785798
return status;
786799
}
787800

788-
vm_id = atoi(argv[1]);
801+
status = atoi(argv[1]);
802+
if (status < 0) {
803+
return -EINVAL;
804+
}
805+
vm_id = (uint16_t)status;
789806
vcpu_id = (uint16_t)atoi(argv[2]);
790807
if (vcpu_id >= phys_cpu_num)
791808
return (-EINVAL);
@@ -848,7 +865,7 @@ int shell_to_sos_console(struct shell *p_shell,
848865
__unused int argc, __unused char **argv)
849866
{
850867
char temp_str[TEMP_STR_SIZE];
851-
int guest_no = 0;
868+
uint16_t guest_no = 0U;
852869

853870
struct vm *vm;
854871
struct vuart *vuart;
@@ -944,7 +961,8 @@ int shell_show_req_info(struct shell *p_shell,
944961
int shell_show_vioapic_info(struct shell *p_shell, int argc, char **argv)
945962
{
946963
char *temp_str = alloc_page();
947-
uint32_t vmid;
964+
uint16_t vmid;
965+
int32_t ret;
948966

949967
if (temp_str == NULL) {
950968
return -ENOMEM;
@@ -955,7 +973,12 @@ int shell_show_vioapic_info(struct shell *p_shell, int argc, char **argv)
955973
snprintf(temp_str, CPU_PAGE_SIZE, "\r\nvmid param needed\r\n");
956974
goto END;
957975
} else {
958-
vmid = atoi(argv[1]);
976+
ret = atoi(argv[1]);
977+
if (ret >= 0) {
978+
vmid = (uint16_t) ret;
979+
} else {
980+
return -EINVAL;
981+
}
959982
}
960983

961984
get_vioapic_info(temp_str, CPU_PAGE_SIZE, vmid);

hypervisor/debug/vuart.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -381,7 +381,7 @@ void vuart_console_rx_chars(uint32_t serial_handle)
381381

382382
struct vuart *vuart_console_active(void)
383383
{
384-
struct vm *vm = get_vm_from_vmid(0);
384+
struct vm *vm = get_vm_from_vmid(0U);
385385

386386
if ((vm != NULL) && (vm->vuart != NULL)) {
387387
struct vuart *vu = vm->vuart;

hypervisor/include/arch/x86/guest/vioapic.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ int vioapic_mmio_access_handler(struct vcpu *vcpu, struct mem_io *mmio,
5555
void *handler_private_data);
5656

5757
#ifdef HV_DEBUG
58-
void get_vioapic_info(char *str, int str_max, int vmid);
58+
void get_vioapic_info(char *str, int str_max, uint16_t vmid);
5959
#endif /* HV_DEBUG */
6060

6161
#endif

hypervisor/include/arch/x86/guest/vm.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@ enum vm_privilege_level {
1616

1717
#define MAX_VM_NAME_LEN 16
1818
struct vm_attr {
19-
int id; /* Virtual machine identifier */
20-
int boot_idx; /* Index indicating the boot sequence for this VM */
19+
uint16_t id; /* Virtual machine identifier */
20+
uint16_t boot_idx; /* Index indicating the boot sequence for this VM */
2121
};
2222

2323
struct vm_hw_info {
@@ -177,7 +177,7 @@ int create_vm(struct vm_description *vm_desc, struct vm **vm);
177177
int prepare_vm0(void);
178178
void vm_fixup(struct vm *vm);
179179

180-
struct vm *get_vm_from_vmid(int vm_id);
180+
struct vm *get_vm_from_vmid(uint16_t vm_id);
181181

182182
extern struct list_head vm_list;
183183
extern spinlock_t vm_list_lock;

0 commit comments

Comments
 (0)