From: Peter Dinda Date: Tue, 1 Sep 2015 20:51:01 +0000 (-0500) Subject: Cleanup and sanity-checking of endianness, dead code, unchecked returns (Coverity... X-Git-Url: http://v3vee.org/palacios/gitweb/gitweb.cgi?a=commitdiff_plain;h=6d3926e16dc1ba6ca0144e65b737e432c48aaa91;p=palacios.git Cleanup and sanity-checking of endianness, dead code, unchecked returns (Coverity static analysis) --- diff --git a/palacios/src/devices/rtl8139.c b/palacios/src/devices/rtl8139.c index 9d4e7c7..e8e10e3 100644 --- a/palacios/src/devices/rtl8139.c +++ b/palacios/src/devices/rtl8139.c @@ -895,7 +895,10 @@ static void rtl8139_rxbuf_write(struct rtl8139_state * nic_state, addr_t guestpa, host_rxbuf; guestpa = (addr_t)regs->rbstart; - v3_gpa_to_hva(&(nic_state->vm->cores[0]), guestpa, &host_rxbuf); + if (v3_gpa_to_hva(&(nic_state->vm->cores[0]), guestpa, &host_rxbuf)) { + PrintError(VM_NONE, VCORE_NONE, "RTL8139: cannot translate address\n"); + return; + } //wrap to the front of rx buffer if (regs->cbr + size > nic_state->rx_bufsize){ @@ -1173,7 +1176,11 @@ static int tx_one_packet(struct rtl8139_state * nic_state, int descriptor){ PrintDebug(VM_NONE, VCORE_NONE, "RTL8139: sending %d bytes from guest memory at 0x%08x\n", txsize, regs->tsad[descriptor]); - v3_gpa_to_hva(&(nic_state->vm->cores[0]), (addr_t)pkt_gpa, &hostva); + if (v3_gpa_to_hva(&(nic_state->vm->cores[0]), (addr_t)pkt_gpa, &hostva)) { + PrintError(VM_NONE, VCORE_NONE, "RTL8139: Cannot translate address\n"); + return -1; + } + pkt = (uchar_t *)hostva; #ifdef V3_CONFIG_DEBUG_RTL8139 diff --git a/palacios/src/devices/vga.c b/palacios/src/devices/vga.c index 037223e..1cf1179 100644 --- a/palacios/src/devices/vga.c +++ b/palacios/src/devices/vga.c @@ -710,7 +710,6 @@ static void render_graphics(struct vga_internal *vga, void *fb) db[2] <<= 2; db[0] <<= 2; } - break; // next 4 pixels use planes 1 and 3 for (p=4;p<8;p++) { diff --git a/palacios/src/palacios/mmu/vmm_shdw_pg_tlb_32.h b/palacios/src/palacios/mmu/vmm_shdw_pg_tlb_32.h index 4940993..d7796e9 100644 --- a/palacios/src/palacios/mmu/vmm_shdw_pg_tlb_32.h +++ b/palacios/src/palacios/mmu/vmm_shdw_pg_tlb_32.h @@ -745,9 +745,6 @@ static int invalidation_cb32_64(struct guest_info * info, page_type_t type, if (pdpe->vmm_info == V3_LARGE_PG) { PrintError(info->vm_info, info, "1 Gigabyte pages not supported\n"); return -1; - - pdpe->present = 0; - return 1; } return 0; diff --git a/palacios/src/palacios/mmu/vmm_shdw_pg_tlb_32pae.h b/palacios/src/palacios/mmu/vmm_shdw_pg_tlb_32pae.h index dd2f88b..492d5a1 100644 --- a/palacios/src/palacios/mmu/vmm_shdw_pg_tlb_32pae.h +++ b/palacios/src/palacios/mmu/vmm_shdw_pg_tlb_32pae.h @@ -727,9 +727,6 @@ static int invalidation_cb32pae_64(struct guest_info * info, page_type_t type, if (pdpe->vmm_info == V3_LARGE_PG) { PrintError(info->vm_info, info, "1 Gigabyte pages not supported\n"); return -1; - - pdpe->present = 0; - return 1; } return 0; diff --git a/palacios/src/palacios/mmu/vmm_shdw_pg_tlb_64.h b/palacios/src/palacios/mmu/vmm_shdw_pg_tlb_64.h index 334c675..0a8bc6d 100644 --- a/palacios/src/palacios/mmu/vmm_shdw_pg_tlb_64.h +++ b/palacios/src/palacios/mmu/vmm_shdw_pg_tlb_64.h @@ -778,9 +778,6 @@ static int invalidation_cb_64(struct guest_info * info, page_type_t type, if (pdpe->vmm_info == V3_LARGE_PG) { PrintError(info->vm_info, info, "1 Gigabyte pages not supported\n"); return -1; - - pdpe->present = 0; - return 1; } return 0; diff --git a/palacios/src/palacios/svm.c b/palacios/src/palacios/svm.c index d78a1dc..7be8f8e 100644 --- a/palacios/src/palacios/svm.c +++ b/palacios/src/palacios/svm.c @@ -1145,9 +1145,15 @@ int v3_start_svm_guest(struct guest_info * info) { linear_addr = get_addr_linear(info, info->rip, &(info->segments.cs)); if (info->mem_mode == PHYSICAL_MEM) { - v3_gpa_to_hva(info, linear_addr, &host_addr); + if (v3_gpa_to_hva(info, linear_addr, &host_addr)) { + PrintError(info->vm_info, info, "Cannot translate address\n"); + break; + } } else if (info->mem_mode == VIRTUAL_MEM) { - v3_gva_to_hva(info, linear_addr, &host_addr); + if (v3_gva_to_hva(info, linear_addr, &host_addr)) { + PrintError(info->vm_info, info, "Cannot translate address\n"); + break; + } } V3_Print(info->vm_info, info, "SVM core %u: Host Address of rip = 0x%p\n", info->vcpu_id, (void *)host_addr); diff --git a/palacios/src/palacios/vmm_debug.c b/palacios/src/palacios/vmm_debug.c index 85bd8d2..8e1819e 100644 --- a/palacios/src/palacios/vmm_debug.c +++ b/palacios/src/palacios/vmm_debug.c @@ -487,14 +487,20 @@ void v3_print_idt(struct guest_info * core, addr_t idtr_base) { if (core->mem_mode == PHYSICAL_MEM) { - v3_gpa_to_hva(core, - get_addr_linear(core, idtr_base, &(core->segments.cs)), - &base_hva); + if (v3_gpa_to_hva(core, + get_addr_linear(core, idtr_base, &(core->segments.cs)), + &base_hva)) { + PrintError(core->vm_info, core, "Cannot translate address\n"); + return; + } PrintError(core->vm_info, core, "Kind of weird that we got here.... physical mem?\n"); } else if (core->mem_mode == VIRTUAL_MEM) { - v3_gva_to_hva(core, - get_addr_linear(core, idtr_base, &(core->segments.cs)), - &base_hva); + if (v3_gva_to_hva(core, + get_addr_linear(core, idtr_base, &(core->segments.cs)), + &base_hva)) { + PrintError(core->vm_info, core, "Cannot translate address\n"); + return; + } } // SANITY CHECK @@ -537,14 +543,20 @@ void v3_print_gdt(struct guest_info * core, addr_t gdtr_base) { } if (core->mem_mode == PHYSICAL_MEM) { - v3_gpa_to_hva(core, - get_addr_linear(core, gdtr_base, &(core->segments.cs)), - &base_hva); + if (v3_gpa_to_hva(core, + get_addr_linear(core, gdtr_base, &(core->segments.cs)), + &base_hva)) { + PrintError(core->vm_info, core, "Cannot translate address\n"); + return; + } PrintError(core->vm_info, core, "Kind of weird that we got here.... physical mem?\n"); } else if (core->mem_mode == VIRTUAL_MEM) { - v3_gva_to_hva(core, - get_addr_linear(core, gdtr_base, &(core->segments.cs)), - &base_hva); + if (v3_gva_to_hva(core, + get_addr_linear(core, gdtr_base, &(core->segments.cs)), + &base_hva)) { + PrintError(core->vm_info, core, "Cannot translate address\n"); + return; + } } // SANITY CHECK @@ -610,13 +622,19 @@ void v3_print_idt(struct guest_info * core, addr_t idtr_base) { } if (core->mem_mode == PHYSICAL_MEM) { - v3_gpa_to_hva(core, - get_addr_linear(core, idtr_base, &(core->segments.cs)), - &base_hva); + if (v3_gpa_to_hva(core, + get_addr_linear(core, idtr_base, &(core->segments.cs)), + &base_hva)) { + PrintError(core->vm_info, core, "Cannot translate address\n"); + return; + } } else if (core->mem_mode == VIRTUAL_MEM) { - v3_gva_to_hva(core, - get_addr_linear(core, idtr_base, &(core->segments.cs)), - &base_hva); + if (v3_gva_to_hva(core, + get_addr_linear(core, idtr_base, &(core->segments.cs)), + &base_hva)) { + PrintError(core->vm_info, core, "Cannot translate address\n"); + return; + } } // SANITY CHECK @@ -660,13 +678,19 @@ void v3_print_gdt(struct guest_info * core, addr_t gdtr_base) { } if (core->mem_mode == PHYSICAL_MEM) { - v3_gpa_to_hva(core, - get_addr_linear(core, gdtr_base, &(core->segments.cs)), - &base_hva); + if (v3_gpa_to_hva(core, + get_addr_linear(core, gdtr_base, &(core->segments.cs)), + &base_hva)) { + PrintError(core->vm_info, core, "Cannot translate address\n"); + return; + } } else if (core->mem_mode == VIRTUAL_MEM) { - v3_gva_to_hva(core, - get_addr_linear(core, gdtr_base, &(core->segments.cs)), - &base_hva); + if (v3_gva_to_hva(core, + get_addr_linear(core, gdtr_base, &(core->segments.cs)), + &base_hva)) { + PrintError(core->vm_info, core, "Cannot translate address\n"); + return; + } } // SANITY CHECK @@ -713,13 +737,19 @@ void v3_print_ldt(struct guest_info * core, addr_t ldtr_base) { } if (core->mem_mode == PHYSICAL_MEM) { - v3_gpa_to_hva(core, - get_addr_linear(core, ldtr_base, &(core->segments.cs)), - &base_hva); + if (v3_gpa_to_hva(core, + get_addr_linear(core, ldtr_base, &(core->segments.cs)), + &base_hva)) { + PrintError(core->vm_info, core, "Cannot translate address\n"); + return; + } } else if (core->mem_mode == VIRTUAL_MEM) { - v3_gva_to_hva(core, - get_addr_linear(core, ldtr_base, &(core->segments.cs)), - &base_hva); + if (v3_gva_to_hva(core, + get_addr_linear(core, ldtr_base, &(core->segments.cs)), + &base_hva)) { + PrintError(core->vm_info, core, "Cannot translate address\n"); + return; + } } // SANITY CHECK @@ -766,13 +796,19 @@ void v3_print_tss(struct guest_info * core, addr_t tr_base) { } if (core->mem_mode == PHYSICAL_MEM) { - v3_gpa_to_hva(core, - get_addr_linear(core, tr_base, &(core->segments.cs)), - &base_hva); + if (v3_gpa_to_hva(core, + get_addr_linear(core, tr_base, &(core->segments.cs)), + &base_hva)) { + PrintError(core->vm_info, core, "Cannot translate address\n"); + return; + } } else if (core->mem_mode == VIRTUAL_MEM) { - v3_gva_to_hva(core, - get_addr_linear(core, tr_base, &(core->segments.cs)), - &base_hva); + if (v3_gva_to_hva(core, + get_addr_linear(core, tr_base, &(core->segments.cs)), + &base_hva)) { + PrintError(core->vm_info, core, "Cannot translate address\n"); + return; + } } // SANITY CHECK diff --git a/palacios/src/palacios/vmx.c b/palacios/src/palacios/vmx.c index 80a52a3..2984de8 100644 --- a/palacios/src/palacios/vmx.c +++ b/palacios/src/palacios/vmx.c @@ -1306,9 +1306,15 @@ int v3_start_vmx_guest(struct guest_info * info) { linear_addr = get_addr_linear(info, info->rip, &(info->segments.cs)); if (info->mem_mode == PHYSICAL_MEM) { - v3_gpa_to_hva(info, linear_addr, &host_addr); + if (v3_gpa_to_hva(info, linear_addr, &host_addr)) { + PrintError(info->vm_info, info, "Cannot translate address\n"); + return -1; + } } else if (info->mem_mode == VIRTUAL_MEM) { - v3_gva_to_hva(info, linear_addr, &host_addr); + if (v3_gva_to_hva(info, linear_addr, &host_addr)) { + PrintError(info->vm_info, info, "Cannot translate address\n"); + return -1; + } } V3_Print(info->vm_info, info, "VMX core %u: Host Address of rip = 0x%p\n", info->vcpu_id, (void *)host_addr);