qemu with hax to log dma reads & writes jcs.org/2018/11/12/vfio

Merge remote-tracking branch 'remotes/kevin/tags/for-upstream' into staging

Multiboot patches

# gpg: Signature made Wed 07 Mar 2018 11:15:17 GMT
# gpg: using RSA key 7F09B272C88F2FD6
# gpg: Good signature from "Kevin Wolf <kwolf@redhat.com>"
# Primary key fingerprint: DC3D EB15 9A9A F95D 3D74 56FE 7F09 B272 C88F 2FD6

* remotes/kevin/tags/for-upstream:
multiboot: fprintf(stderr...) -> error_report()
multiboot: Use header names when displaying fields
multiboot: Remove unused variables from multiboot.c
multiboot: bss_end_addr can be zero

Signed-off-by: Peter Maydell <peter.maydell@linaro.org>

+38 -39
+38 -39
hw/i386/multiboot.c
··· 31 31 #include "hw/loader.h" 32 32 #include "elf.h" 33 33 #include "sysemu/sysemu.h" 34 + #include "qemu/error-report.h" 34 35 35 36 /* Show multiboot debug output */ 36 37 //#define DEBUG_MULTIBOOT 37 38 38 39 #ifdef DEBUG_MULTIBOOT 39 - #define mb_debug(a...) fprintf(stderr, ## a) 40 + #define mb_debug(a...) error_report(a) 40 41 #else 41 42 #define mb_debug(a...) 42 43 #endif ··· 137 138 stl_p(p + MB_MOD_END, end); 138 139 stl_p(p + MB_MOD_CMDLINE, cmdline_phys); 139 140 140 - mb_debug("mod%02d: "TARGET_FMT_plx" - "TARGET_FMT_plx"\n", 141 + mb_debug("mod%02d: "TARGET_FMT_plx" - "TARGET_FMT_plx, 141 142 s->mb_mods_count, start, end); 142 143 143 144 s->mb_mods_count++; ··· 179 180 if (!is_multiboot) 180 181 return 0; /* no multiboot */ 181 182 182 - mb_debug("qemu: I believe we found a multiboot image!\n"); 183 + mb_debug("qemu: I believe we found a multiboot image!"); 183 184 memset(bootinfo, 0, sizeof(bootinfo)); 184 185 memset(&mbs, 0, sizeof(mbs)); 185 186 186 187 if (flags & 0x00000004) { /* MULTIBOOT_HEADER_HAS_VBE */ 187 - fprintf(stderr, "qemu: multiboot knows VBE. we don't.\n"); 188 + error_report("qemu: multiboot knows VBE. we don't."); 188 189 } 189 190 if (!(flags & 0x00010000)) { /* MULTIBOOT_HEADER_HAS_ADDR */ 190 191 uint64_t elf_entry; ··· 193 194 fclose(f); 194 195 195 196 if (((struct elf64_hdr*)header)->e_machine == EM_X86_64) { 196 - fprintf(stderr, "Cannot load x86-64 image, give a 32bit one.\n"); 197 + error_report("Cannot load x86-64 image, give a 32bit one."); 197 198 exit(1); 198 199 } 199 200 ··· 201 202 &elf_low, &elf_high, 0, I386_ELF_MACHINE, 202 203 0, 0); 203 204 if (kernel_size < 0) { 204 - fprintf(stderr, "Error while loading elf kernel\n"); 205 + error_report("Error while loading elf kernel"); 205 206 exit(1); 206 207 } 207 208 mh_load_addr = elf_low; ··· 210 211 211 212 mbs.mb_buf = g_malloc(mb_kernel_size); 212 213 if (rom_copy(mbs.mb_buf, mh_load_addr, mb_kernel_size) != mb_kernel_size) { 213 - fprintf(stderr, "Error while fetching elf kernel from rom\n"); 214 + error_report("Error while fetching elf kernel from rom"); 214 215 exit(1); 215 216 } 216 217 217 - mb_debug("qemu: loading multiboot-elf kernel (%#x bytes) with entry %#zx\n", 218 - mb_kernel_size, (size_t)mh_entry_addr); 218 + mb_debug("qemu: loading multiboot-elf kernel " 219 + "(%#x bytes) with entry %#zx", 220 + mb_kernel_size, (size_t)mh_entry_addr); 219 221 } else { 220 222 /* Valid if mh_flags sets MULTIBOOT_HEADER_HAS_ADDR. */ 221 223 uint32_t mh_header_addr = ldl_p(header+i+12); ··· 224 226 225 227 mh_load_addr = ldl_p(header+i+16); 226 228 if (mh_header_addr < mh_load_addr) { 227 - fprintf(stderr, "invalid mh_load_addr address\n"); 229 + error_report("invalid load_addr address"); 228 230 exit(1); 229 231 } 230 232 ··· 233 235 mh_entry_addr = ldl_p(header+i+28); 234 236 235 237 if (mh_load_end_addr) { 236 - if (mh_bss_end_addr < mh_load_addr) { 237 - fprintf(stderr, "invalid mh_bss_end_addr address\n"); 238 - exit(1); 239 - } 240 - mb_kernel_size = mh_bss_end_addr - mh_load_addr; 241 - 242 238 if (mh_load_end_addr < mh_load_addr) { 243 - fprintf(stderr, "invalid mh_load_end_addr address\n"); 239 + error_report("invalid load_end_addr address"); 244 240 exit(1); 245 241 } 246 242 mb_load_size = mh_load_end_addr - mh_load_addr; 247 243 } else { 248 244 if (kernel_file_size < mb_kernel_text_offset) { 249 - fprintf(stderr, "invalid kernel_file_size\n"); 245 + error_report("invalid kernel_file_size"); 246 + exit(1); 247 + } 248 + mb_load_size = kernel_file_size - mb_kernel_text_offset; 249 + } 250 + if (mh_bss_end_addr) { 251 + if (mh_bss_end_addr < (mh_load_addr + mb_load_size)) { 252 + error_report("invalid bss_end_addr address"); 250 253 exit(1); 251 254 } 252 - mb_kernel_size = kernel_file_size - mb_kernel_text_offset; 253 - mb_load_size = mb_kernel_size; 255 + mb_kernel_size = mh_bss_end_addr - mh_load_addr; 256 + } else { 257 + mb_kernel_size = mb_load_size; 254 258 } 255 259 256 - /* Valid if mh_flags sets MULTIBOOT_HEADER_HAS_VBE. 257 - uint32_t mh_mode_type = ldl_p(header+i+32); 258 - uint32_t mh_width = ldl_p(header+i+36); 259 - uint32_t mh_height = ldl_p(header+i+40); 260 - uint32_t mh_depth = ldl_p(header+i+44); */ 261 - 262 - mb_debug("multiboot: mh_header_addr = %#x\n", mh_header_addr); 263 - mb_debug("multiboot: mh_load_addr = %#x\n", mh_load_addr); 264 - mb_debug("multiboot: mh_load_end_addr = %#x\n", mh_load_end_addr); 265 - mb_debug("multiboot: mh_bss_end_addr = %#x\n", mh_bss_end_addr); 266 - mb_debug("qemu: loading multiboot kernel (%#x bytes) at %#x\n", 260 + mb_debug("multiboot: header_addr = %#x", mh_header_addr); 261 + mb_debug("multiboot: load_addr = %#x", mh_load_addr); 262 + mb_debug("multiboot: load_end_addr = %#x", mh_load_end_addr); 263 + mb_debug("multiboot: bss_end_addr = %#x", mh_bss_end_addr); 264 + mb_debug("qemu: loading multiboot kernel (%#x bytes) at %#x", 267 265 mb_load_size, mh_load_addr); 268 266 269 267 mbs.mb_buf = g_malloc(mb_kernel_size); 270 268 fseek(f, mb_kernel_text_offset, SEEK_SET); 271 269 if (fread(mbs.mb_buf, 1, mb_load_size, f) != mb_load_size) { 272 - fprintf(stderr, "fread() failed\n"); 270 + error_report("fread() failed"); 273 271 exit(1); 274 272 } 275 273 memset(mbs.mb_buf + mb_load_size, 0, mb_kernel_size - mb_load_size); ··· 323 321 hwaddr c = mb_add_cmdline(&mbs, tmpbuf); 324 322 if ((next_space = strchr(tmpbuf, ' '))) 325 323 *next_space = '\0'; 326 - mb_debug("multiboot loading module: %s\n", tmpbuf); 324 + mb_debug("multiboot loading module: %s", tmpbuf); 327 325 mb_mod_length = get_image_size(tmpbuf); 328 326 if (mb_mod_length < 0) { 329 - fprintf(stderr, "Failed to open file '%s'\n", tmpbuf); 327 + error_report("Failed to open file '%s'", tmpbuf); 330 328 exit(1); 331 329 } 332 330 ··· 337 335 mb_add_mod(&mbs, mbs.mb_buf_phys + offs, 338 336 mbs.mb_buf_phys + offs + mb_mod_length, c); 339 337 340 - mb_debug("mod_start: %p\nmod_end: %p\n cmdline: "TARGET_FMT_plx"\n", 338 + mb_debug("mod_start: %p\nmod_end: %p\n cmdline: "TARGET_FMT_plx, 341 339 (char *)mbs.mb_buf + offs, 342 340 (char *)mbs.mb_buf + offs + mb_mod_length, c); 343 341 initrd_filename = next_initrd+1; ··· 365 363 stl_p(bootinfo + MBI_BOOT_DEVICE, 0x8000ffff); /* XXX: use the -boot switch? */ 366 364 stl_p(bootinfo + MBI_MMAP_ADDR, ADDR_E820_MAP); 367 365 368 - mb_debug("multiboot: mh_entry_addr = %#x\n", mh_entry_addr); 369 - mb_debug(" mb_buf_phys = "TARGET_FMT_plx"\n", mbs.mb_buf_phys); 370 - mb_debug(" mod_start = "TARGET_FMT_plx"\n", mbs.mb_buf_phys + mbs.offset_mods); 371 - mb_debug(" mb_mods_count = %d\n", mbs.mb_mods_count); 366 + mb_debug("multiboot: entry_addr = %#x", mh_entry_addr); 367 + mb_debug(" mb_buf_phys = "TARGET_FMT_plx, mbs.mb_buf_phys); 368 + mb_debug(" mod_start = "TARGET_FMT_plx, 369 + mbs.mb_buf_phys + mbs.offset_mods); 370 + mb_debug(" mb_mods_count = %d", mbs.mb_mods_count); 372 371 373 372 /* save bootinfo off the stack */ 374 373 mb_bootinfo_data = g_memdup(bootinfo, sizeof(bootinfo));