]> xenbits.xensource.com Git - unikraft/unikraft.git/commitdiff
plat/kvm: Check return code of all memory region inserting methods
authorSergiu Moga <sergiu@unikraft.io>
Mon, 14 Aug 2023 15:50:04 +0000 (18:50 +0300)
committerUnikraft <monkey@unikraft.io>
Tue, 15 Aug 2023 14:35:12 +0000 (14:35 +0000)
Make sure that we do check the return codes of all of the memory region
inserting methods so that we can crash in case of failure, instead
of letting the system run with a corrupted state.

Signed-off-by: Sergiu Moga <sergiu@unikraft.io>
Reviewed-by: Marco Schlumpp <marco@unikraft.io>
Reviewed-by: Michalis Pappas <michalis@unikraft.io>
Approved-by: Razvan Deaconescu <razvand@unikraft.io>
Tested-by: Unikraft CI <monkey@unikraft.io>
GitHub-Closes: #1052

plat/kvm/efi.c
plat/kvm/x86/lxboot.c
plat/kvm/x86/multiboot.c

index b6ec443829ade849829891d794b2dd784a115d41..d267be0f0809d5ebd81f8076e9688d376fa9365e 100644 (file)
@@ -335,10 +335,14 @@ static void uk_efi_setup_bootinfo_mrds(struct ukplat_bootinfo *bi)
                        uk_efi_crash("Failed to insert mrd\n");
        }
 
-       ukplat_memregion_list_coalesce(&bi->mrds);
+       rc = ukplat_memregion_list_coalesce(&bi->mrds);
+       if (unlikely(rc))
+               uk_efi_crash("Failed to coalesce memory regions\n");
 
 #if defined(__X86_64__)
-       ukplat_memregion_alloc_sipi_vect();
+       rc = ukplat_memregion_alloc_sipi_vect();
+       if (unlikely(rc))
+               uk_efi_crash("Failed to insert SIPI vector region\n");
 #endif
 }
 
index b9e37d4cda33873f60096886323f67c7fe81b0fe..f0c152587bb0d53b7bb02c9af2e53dd355560acf 100644 (file)
@@ -145,6 +145,7 @@ lxboot_init_mem(struct ukplat_bootinfo *bi, struct lxboot_params *bp)
 void lxboot_entry(struct lcpu *lcpu, struct lxboot_params *bp)
 {
        struct ukplat_bootinfo *bi;
+       int rc;
 
        bi = ukplat_bootinfo_get();
        if (unlikely(!bi))
@@ -156,7 +157,9 @@ void lxboot_entry(struct lcpu *lcpu, struct lxboot_params *bp)
        lxboot_init_cmdline(bi, bp);
        lxboot_init_initrd(bi, bp);
        lxboot_init_mem(bi, bp);
-       ukplat_memregion_list_coalesce(&bi->mrds);
+       rc = ukplat_memregion_list_coalesce(&bi->mrds);
+       if (unlikely(rc))
+               lxboot_crash(rc, "Could not coalesce memory regions");
 
        memcpy(bi->bootprotocol, "lxboot", sizeof("lxboot"));
 
index b41d9fa9e4af8f8eb0b88a424d44776fb360f827..8dfcc52514072a8a2bbb9e20f2e0c8779fe9a847 100644 (file)
@@ -50,6 +50,7 @@ void multiboot_entry(struct lcpu *lcpu, struct multiboot_info *mi)
        __sz offset, cmdline_len;
        __paddr_t start, end;
        __u32 i;
+       int rc;
 
        bi = ukplat_bootinfo_get();
        if (unlikely(!bi))
@@ -62,7 +63,9 @@ void multiboot_entry(struct lcpu *lcpu, struct multiboot_info *mi)
        do_uk_reloc_kmrds(0, 0);
 
        /* Ensure that the memory map contains the legacy high mem area */
-       ukplat_memregion_list_insert_legacy_hi_mem(&bi->mrds);
+       rc = ukplat_memregion_list_insert_legacy_hi_mem(&bi->mrds);
+       if (unlikely(rc))
+               multiboot_crash("Could not insert legacy memory region", rc);
 
        /* Add the cmdline */
        if (mi->flags & MULTIBOOT_INFO_CMDLINE) {
@@ -153,9 +156,13 @@ void multiboot_entry(struct lcpu *lcpu, struct multiboot_info *mi)
                }
        }
 
-       ukplat_memregion_list_coalesce(&bi->mrds);
+       rc = ukplat_memregion_list_coalesce(&bi->mrds);
+       if (unlikely(rc))
+               multiboot_crash("Could not coalesce memory regions", rc);
 
-       ukplat_memregion_alloc_sipi_vect();
+       rc = ukplat_memregion_alloc_sipi_vect();
+       if (unlikely(rc))
+               multiboot_crash("Could not insert SIPI vector region", rc);
 
        _ukplat_entry(lcpu, bi);
 }