diff --git a/devicemodel/arch/x86/pm.c b/devicemodel/arch/x86/pm.c index ee8731dbe..32649741e 100644 --- a/devicemodel/arch/x86/pm.c +++ b/devicemodel/arch/x86/pm.c @@ -67,12 +67,12 @@ reset_handler(struct vmctx *ctx, int vcpu, int in, int port, int bytes, reset_control = *eax; if (*eax & 0x8) { - fprintf(stderr, "full reset\r\n"); + pr_notice("full reset\r\n"); vm_suspend(ctx, VM_SUSPEND_FULL_RESET); mevent_notify(); reset_control = 0; } else if (*eax & 0x4) { - fprintf(stderr, "system reset\r\n"); + pr_notice("system reset\r\n"); vm_suspend(ctx, VM_SUSPEND_SYSTEM_RESET); mevent_notify(); } diff --git a/devicemodel/arch/x86/power_button.c b/devicemodel/arch/x86/power_button.c index 8649906a6..d28a30243 100644 --- a/devicemodel/arch/x86/power_button.c +++ b/devicemodel/arch/x86/power_button.c @@ -110,14 +110,14 @@ open_power_button_input_device(const char *drv, const char *dir) ninput = scandir(dir, &input_dirs, input_dir_filter, alphasort); if (ninput < 0) { - fprintf(stderr, "failed to scan power button %s\n", + pr_err("failed to scan power button %s\n", dir); goto err; } else if (ninput == 1) { rc = snprintf(path, sizeof(path), "%s/%s", dir, input_dirs[0]->d_name); if (rc < 0 || rc >= sizeof(path)) { - fprintf(stderr, "failed to set power button path %d\n", + pr_err("failed to set power button path %d\n", rc); goto err_input; } @@ -129,7 +129,7 @@ open_power_button_input_device(const char *drv, const char *dir) nevent = scandir(path, &event_dirs, event_dir_filter, alphasort); if (nevent < 0) { - fprintf(stderr, "failed to get power button event %s\n", + pr_err("failed to get power button event %s\n", path); goto err_input; } else if (nevent == 1) { @@ -138,16 +138,16 @@ open_power_button_input_device(const char *drv, const char *dir) rc = snprintf(name, sizeof(name), "/dev/input/%s", event_dirs[0]->d_name); if (rc < 0 || rc >= sizeof(name)) { - fprintf(stderr, "power button error %d\n", rc); + pr_err("power button error %d\n", rc); goto err_input; } } else { - fprintf(stderr, "power button event number error %d\n", + pr_err("power button event number error %d\n", nevent); goto err_event; } } else { - fprintf(stderr, "power button input number error %d\n", nevent); + pr_err("power button input number error %d\n", nevent); goto err_input; } @@ -203,7 +203,7 @@ power_button_init(struct vmctx *ctx) if (input_evt0 == NULL) { pwrbtn_fd = open_native_power_button(); if (pwrbtn_fd < 0) - fprintf(stderr, "open power button error=%d\n", + pr_err("open power button error=%d\n", errno); else input_evt0 = mevent_add(pwrbtn_fd, EVF_READ, @@ -217,8 +217,7 @@ power_button_init(struct vmctx *ctx) if (monitor_run == false) { if (monitor_register_vm_ops(&vm_ops, ctx, POWER_BUTTON_NAME) < 0) - fprintf(stderr, - "failed to register vm ops for power button\n"); + pr_err("failed to register vm ops for power button\n"); else monitor_run = true; } diff --git a/devicemodel/core/main.c b/devicemodel/core/main.c index 8c2a66e41..bd65beaac 100644 --- a/devicemodel/core/main.c +++ b/devicemodel/core/main.c @@ -257,7 +257,7 @@ add_cpu(struct vmctx *ctx, int vcpu_num) for (i = 0; i < vcpu_num; i++) { error = vm_create_vcpu(ctx, (uint16_t)i); if (error != 0) { - fprintf(stderr, "ERROR: could not create VCPU %d\n", i); + pr_err("ERROR: could not create VCPU %d\n", i); return error; } CPU_SET_ATOMIC(i, &cpumask); @@ -278,7 +278,7 @@ static int delete_cpu(struct vmctx *ctx, int vcpu) { if (!CPU_ISSET(vcpu, &cpumask)) { - fprintf(stderr, "Attempting to delete unknown cpu %d\n", vcpu); + pr_err("Attempting to delete unknown cpu %d\n", vcpu); exit(1); } @@ -310,7 +310,7 @@ vmexit_inout(struct vmctx *ctx, struct vhm_request *vhm_req, int *pvcpu) error = emulate_inout(ctx, pvcpu, &vhm_req->reqs.pio); if (error) { - fprintf(stderr, "Unhandled %s%c 0x%04x\n", + pr_err("Unhandled %s%c 0x%04x\n", in ? "in" : "out", bytes == 1 ? 'b' : (bytes == 2 ? 'w' : 'l'), port); @@ -331,11 +331,11 @@ vmexit_mmio_emul(struct vmctx *ctx, struct vhm_request *vhm_req, int *pvcpu) if (err) { if (err == -ESRCH) - fprintf(stderr, "Unhandled memory access to 0x%lx\n", + pr_err("Unhandled memory access to 0x%lx\n", vhm_req->reqs.mmio.address); - fprintf(stderr, "Failed to emulate instruction ["); - fprintf(stderr, "mmio address 0x%lx, size %ld", + pr_err("Failed to emulate instruction ["); + pr_err("mmio address 0x%lx, size %ld", vhm_req->reqs.mmio.address, vhm_req->reqs.mmio.size); @@ -358,7 +358,7 @@ vmexit_pci_emul(struct vmctx *ctx, struct vhm_request *vhm_req, int *pvcpu) vhm_req->reqs.pci.size, &vhm_req->reqs.pci.value); if (err) { - fprintf(stderr, "Unhandled pci cfg rw at %x:%x.%x reg 0x%x\n", + pr_err("Unhandled pci cfg rw at %x:%x.%x reg 0x%x\n", vhm_req->reqs.pci.bus, vhm_req->reqs.pci.dev, vhm_req->reqs.pci.func, @@ -393,7 +393,7 @@ handle_vmexit(struct vmctx *ctx, struct vhm_request *vhm_req, int vcpu) exitcode = vhm_req->type; if (exitcode >= VM_EXITCODE_MAX || handler[exitcode] == NULL) { - fprintf(stderr, "handle vmexit: unexpected exitcode 0x%x\n", + pr_err("handle vmexit: unexpected exitcode 0x%x\n", exitcode); exit(1); } diff --git a/devicemodel/core/mevent.c b/devicemodel/core/mevent.c index 2c3a84886..e8a8bef81 100644 --- a/devicemodel/core/mevent.c +++ b/devicemodel/core/mevent.c @@ -42,6 +42,7 @@ #include "mevent.h" #include "vmmapi.h" +#include "log.h" #define MEVENT_MAX 64 @@ -419,7 +420,7 @@ mevent_dispatch(void) */ pipev = mevent_add(mevent_pipefd[0], EVF_READ, mevent_pipe_read, NULL, NULL, NULL); if (!pipev) { - fprintf(stderr, "pipefd mevent_add failed\n"); + pr_err("pipefd mevent_add failed\n"); exit(0); } diff --git a/devicemodel/core/monitor.c b/devicemodel/core/monitor.c index 471aea34a..fdc4e9550 100644 --- a/devicemodel/core/monitor.c +++ b/devicemodel/core/monitor.c @@ -444,7 +444,7 @@ static void handle_blkrescan(struct mngr_msg *msg, int client_fd, void *param) if (!count) { ack.data.err = -1; - fprintf(stderr, "No handler for id:%u\r\n", msg->msgid); + pr_err("No handler for id:%u\r\n", msg->msgid); } else ack.data.err = ret; diff --git a/devicemodel/core/mptbl.c b/devicemodel/core/mptbl.c index 4290983bf..3fee782cb 100644 --- a/devicemodel/core/mptbl.c +++ b/devicemodel/core/mptbl.c @@ -290,7 +290,7 @@ mptable_build(struct vmctx *ctx, int ncpu) startaddr = paddr_guest2host(ctx, MPTABLE_BASE, MPTABLE_MAX_LENGTH); if (startaddr == NULL) { - fprintf(stderr, "mptable requires mapped mem\n"); + pr_err("mptable requires mapped mem\n"); return -1; } @@ -301,9 +301,9 @@ mptable_build(struct vmctx *ctx, int ncpu) */ for (bus = 1; bus <= PCI_BUSMAX; bus++) { if (pci_bus_configured(bus)) { - fprintf(stderr, "MPtable is incompatible with " + pr_err("MPtable is incompatible with " "multiple PCI hierarchies.\r\n"); - fprintf(stderr, "MPtable generation can be disabled " + pr_err("MPtable generation can be disabled " "by passing the -Y option to acrn-dm.\r\n"); return -1; } diff --git a/devicemodel/core/sw_load_common.c b/devicemodel/core/sw_load_common.c index 933464fef..a94176438 100644 --- a/devicemodel/core/sw_load_common.c +++ b/devicemodel/core/sw_load_common.c @@ -148,8 +148,7 @@ check_image(char *path, size_t size_limit, size_t *size) fp = fopen(path, "r"); if (fp == NULL) { - fprintf(stderr, - "SW_LOAD ERR: image file failed to open\n"); + pr_err("SW_LOAD ERR: image file failed to open\n"); return -1; } @@ -157,8 +156,7 @@ check_image(char *path, size_t size_limit, size_t *size) len = ftell(fp); if (len == 0 || (size_limit && len > size_limit)) { - fprintf(stderr, - "SW_LOAD ERR: file is %s\n", + pr_err("SW_LOAD ERR: file is %s\n", len ? "too large" : "empty"); fclose(fp); return -1; diff --git a/devicemodel/core/sw_load_elf.c b/devicemodel/core/sw_load_elf.c index ff4a85d39..fdd586740 100644 --- a/devicemodel/core/sw_load_elf.c +++ b/devicemodel/core/sw_load_elf.c @@ -44,6 +44,7 @@ #include "vmmapi.h" #include "sw_load.h" #include "acpi.h" +#include "log.h" #define ELF_BUF_LEN (1024UL*8UL) #define MULTIBOOT_HEAD_MAGIC (0x1BADB002U) @@ -119,22 +120,21 @@ static int load_elf32(struct vmctx *ctx, FILE *fp, void *buf) phd_size = elf32_header->e_phentsize * elf32_header->e_phnum; elf32_phdr_bk = elf32_phdr = (Elf32_Phdr *)calloc(1, phd_size); if (elf32_phdr == NULL) { - fprintf(stderr, "Can't allocate memory for elf program header\n"); + pr_err("Can't allocate memory for elf program header\n"); return -1; } fseek(fp, elf32_header->e_phoff, SEEK_SET); read_len = fread((void *)elf32_phdr, 1, phd_size, fp); if (read_len != phd_size) { - fprintf(stderr, "can't get %ld data from elf file\n", phd_size); + pr_err("can't get %ld data from elf file\n", phd_size); } for (i = 0; i < elf32_header->e_phnum; i++) { if (elf32_phdr->p_type == PT_LOAD) { if ((elf32_phdr->p_vaddr + elf32_phdr->p_memsz) > ctx->lowmem) { - fprintf(stderr, - "No enough memory to load elf file\n"); + pr_err("No enough memory to load elf file\n"); free(elf32_phdr_bk); return -1; } @@ -148,7 +148,7 @@ static int load_elf32(struct vmctx *ctx, FILE *fp, void *buf) fseek(fp, elf32_phdr->p_offset, SEEK_SET); read_len = fread(seg_ptr, 1, elf32_phdr->p_filesz, fp); if (read_len != elf32_phdr->p_filesz) { - fprintf(stderr, "Can't get %d data\n", + pr_err("Can't get %d data\n", elf32_phdr->p_filesz); } } @@ -174,20 +174,20 @@ acrn_load_elf(struct vmctx *ctx, char *elf_file_name, unsigned long *entry, elf_buf = calloc(1, ELF_BUF_LEN); if (elf_buf == NULL) { - fprintf(stderr, "Can't allocate elf buf\r\n"); + pr_err("Can't allocate elf buf\r\n"); return -1; } fp = fopen(elf_file_name, "r"); if (fp == NULL) { - fprintf(stderr, "Can't open elf file: %s\r\n", elf_file_name); + pr_err("Can't open elf file: %s\r\n", elf_file_name); free(elf_buf); return -1; } read_len = fread(elf_buf, 1, ELF_BUF_LEN, fp); if (read_len != ELF_BUF_LEN) { - fprintf(stderr, "Can't get %ld data from elf file\n", + pr_err("Can't get %ld data from elf file\n", ELF_BUF_LEN); } @@ -226,7 +226,7 @@ acrn_load_elf(struct vmctx *ctx, char *elf_file_name, unsigned long *entry, (elf_ehdr->e_ident[EI_MAG1] != ELFMAG1) || (elf_ehdr->e_ident[EI_MAG2] != ELFMAG2) || (elf_ehdr->e_ident[EI_MAG3] != ELFMAG3)) { - fprintf(stderr, "This is not elf file\n"); + pr_err("This is not elf file\n"); fclose(fp); free(elf_buf); @@ -236,7 +236,7 @@ acrn_load_elf(struct vmctx *ctx, char *elf_file_name, unsigned long *entry, if (elf_ehdr->e_ident[EI_CLASS] == ELFCLASS32) { ret = load_elf32(ctx, fp, elf_buf); } else { - fprintf(stderr, "No available 64bit elf loader ready yet\n"); + pr_err("No available 64bit elf loader ready yet\n"); fclose(fp); free(elf_buf); return -1; @@ -314,8 +314,7 @@ acrn_sw_load_elf(struct vmctx *ctx) mi->mem_upper = GDT_LOAD_OFF(ctx) / 1024U; ctx->bsp_regs.vcpu_regs.gprs.rbx = MULTIBOOT_OFFSET; } else { - fprintf(stderr, - "Invalid multiboot header in elf binary\n"); + pr_err("Invalid multiboot header in elf binary\n"); return -1; } } diff --git a/devicemodel/core/sw_load_ovmf.c b/devicemodel/core/sw_load_ovmf.c index 03ea80aee..b494d46ff 100644 --- a/devicemodel/core/sw_load_ovmf.c +++ b/devicemodel/core/sw_load_ovmf.c @@ -118,8 +118,7 @@ acrn_prepare_ovmf(struct vmctx *ctx) fp = fopen(ovmf_path, "r"); if (fp == NULL) { - fprintf(stderr, - "SW_LOAD ERR: could not open ovmf file: %s\n", + pr_err("SW_LOAD ERR: could not open ovmf file: %s\n", ovmf_path); return -1; } @@ -127,8 +126,7 @@ acrn_prepare_ovmf(struct vmctx *ctx) fseek(fp, 0, SEEK_END); if (ftell(fp) != ovmf_size) { - fprintf(stderr, - "SW_LOAD ERR: ovmf file changed\n"); + pr_err("SW_LOAD ERR: ovmf file changed\n"); fclose(fp); return -1; } @@ -138,14 +136,13 @@ acrn_prepare_ovmf(struct vmctx *ctx) sizeof(char), ovmf_size, fp); if (read < ovmf_size) { - fprintf(stderr, - "SW_LOAD ERR: could not read whole partition blob\n"); + pr_err("SW_LOAD ERR: could not read whole partition blob\n"); fclose(fp); return -1; } fclose(fp); - printf("SW_LOAD: partition blob %s size %lu copy to guest 0x%lx\n", + pr_info("SW_LOAD: partition blob %s size %lu copy to guest 0x%lx\n", ovmf_path, ovmf_size, OVMF_TOP(ctx) - ovmf_size); return 0; } @@ -176,7 +173,7 @@ acrn_sw_load_ovmf(struct vmctx *ctx) strncpy(e820->signature, "820", sizeof(e820->signature)); e820->nentries = acrn_create_e820_table(ctx, e820->map); - printf("SW_LOAD: ovmf_entry 0x%lx\n", OVMF_TOP(ctx) - 16); + pr_info("SW_LOAD: ovmf_entry 0x%lx\n", OVMF_TOP(ctx) - 16); /* set guest bsp state. Will call hypercall set bsp state * after bsp is created. @@ -213,8 +210,7 @@ acrn_writeback_ovmf_nvstorage(struct vmctx *ctx) fp = fopen(ovmf_path, "r+"); if (fp == NULL) { - fprintf(stderr, - "OVMF_WRITEBACK ERR: could not open ovmf file: %s\n", + pr_err("OVMF_WRITEBACK ERR: could not open ovmf file: %s\n", ovmf_path); return -1; } @@ -222,8 +218,7 @@ acrn_writeback_ovmf_nvstorage(struct vmctx *ctx) fseek(fp, 0, SEEK_END); if (ftell(fp) != ovmf_size) { - fprintf(stderr, - "SW_LOAD ERR: ovmf file changed\n"); + pr_err("SW_LOAD ERR: ovmf file changed\n"); fclose(fp); return -1; } @@ -233,8 +228,7 @@ acrn_writeback_ovmf_nvstorage(struct vmctx *ctx) sizeof(char), OVMF_NVSTORAGE_SZ, fp); if (write < OVMF_NVSTORAGE_SZ) { - fprintf(stderr, - "OVMF_WRITEBACK ERR: could not write back OVMF\n"); + pr_err("OVMF_WRITEBACK ERR: could not write back OVMF\n"); fclose(fp); return -1; } diff --git a/devicemodel/core/sw_load_vsbl.c b/devicemodel/core/sw_load_vsbl.c index 789950fb2..c4729c24f 100644 --- a/devicemodel/core/sw_load_vsbl.c +++ b/devicemodel/core/sw_load_vsbl.c @@ -214,8 +214,7 @@ acrn_prepare_vsbl(struct vmctx *ctx) fp = fopen(vsbl_path, "r"); if (fp == NULL) { - fprintf(stderr, - "SW_LOAD ERR: could not open vsbl file: %s\n", + pr_err("SW_LOAD ERR: could not open vsbl file: %s\n", vsbl_path); return -1; } @@ -223,8 +222,7 @@ acrn_prepare_vsbl(struct vmctx *ctx) fseek(fp, 0, SEEK_END); if (ftell(fp) != vsbl_size) { - fprintf(stderr, - "SW_LOAD ERR: vsbl file changed\n"); + pr_err("SW_LOAD ERR: vsbl file changed\n"); fclose(fp); return -1; } @@ -233,8 +231,7 @@ acrn_prepare_vsbl(struct vmctx *ctx) read = fread(ctx->baseaddr + VSBL_TOP(ctx) - vsbl_size, sizeof(char), vsbl_size, fp); if (read < vsbl_size) { - fprintf(stderr, - "SW_LOAD ERR: could not read whole partition blob\n"); + pr_err("SW_LOAD ERR: could not read whole partition blob\n"); fclose(fp); return -1; } diff --git a/devicemodel/core/vrpmb.c b/devicemodel/core/vrpmb.c index 201ea7a1f..98b05e214 100644 --- a/devicemodel/core/vrpmb.c +++ b/devicemodel/core/vrpmb.c @@ -32,6 +32,7 @@ #include "types.h" #include "vrpmb.h" +#include "log.h" #define DRNG_MAX_RETRIES 5U @@ -51,12 +52,12 @@ int get_vrpmb_key(uint8_t *out, size_t size) int i; if (!out) { - fprintf(stderr, "%s: Invalid output pointer\n", __func__); + pr_err("%s: Invalid output pointer\n", __func__); return 0; } if (size != RPMB_KEY_LEN) { - fprintf(stderr, "%s: Invalid input key size\n", __func__); + pr_err("%s: Invalid input key size\n", __func__); return 0; } @@ -70,7 +71,7 @@ int get_vrpmb_key(uint8_t *out, size_t size) } if (vrkey.initialized != true) { - fprintf(stderr, "%s: unable to generate random key!\n", __func__); + pr_err("%s: unable to generate random key!\n", __func__); return 0; } } diff --git a/devicemodel/hw/block_if.c b/devicemodel/hw/block_if.c index 9beb6b4d4..880981b5a 100644 --- a/devicemodel/hw/block_if.c +++ b/devicemodel/hw/block_if.c @@ -46,6 +46,7 @@ #include "block_if.h" #include "ahci.h" #include "dm_string.h" +#include "log.h" /* * Notes: @@ -478,7 +479,7 @@ sub_file_unlock(struct blockif_ctxt *bc) DPRINTF(("blockif: release file lock...\n")); fl->l_type = F_UNLCK; if (fcntl(bc->fd, F_OFD_SETLK, fl) == -1) { - fprintf(stderr, "blockif: failed to unlock subfile!\n"); + pr_err("blockif: failed to unlock subfile!\n"); exit(1); } DPRINTF(("blockif: release done\n")); @@ -579,7 +580,7 @@ blockif_open(const char *optstr, const char *ident) else goto err; } else { - fprintf(stderr, "Invalid device option \"%s\"\n", cp); + pr_err("Invalid device option \"%s\"\n", cp); goto err; } } @@ -619,7 +620,7 @@ blockif_open(const char *optstr, const char *ident) /* get size */ err_code = ioctl(fd, BLKGETSIZE, &sz); if (err_code) { - fprintf(stderr, "error %d getting block size!\n", + pr_err("error %d getting block size!\n", err_code); size = sbuf.st_size; /* set default value */ } else { @@ -641,7 +642,7 @@ blockif_open(const char *optstr, const char *ident) /* get physical sector size */ err_code = ioctl(fd, BLKPBSZGET, &psectsz); if (err_code) { - fprintf(stderr, "error %d getting physical sectsz!\n", + pr_err("error %d getting physical sectsz!\n", err_code); psectsz = DEV_BSIZE; /* set default physical size */ } @@ -668,7 +669,7 @@ blockif_open(const char *optstr, const char *ident) if (ssopt != 0) { if (!powerof2(ssopt) || !powerof2(pssopt) || ssopt < 512 || ssopt > pssopt) { - fprintf(stderr, "Invalid sector size %d/%d\n", + pr_err("Invalid sector size %d/%d\n", ssopt, pssopt); goto err; } @@ -682,8 +683,7 @@ blockif_open(const char *optstr, const char *ident) */ if (S_ISCHR(sbuf.st_mode)) { if (ssopt < sectsz || (ssopt % sectsz) != 0) { - fprintf(stderr, - "Sector size %d incompatible with underlying device sector size %d\n", + pr_err("Sector size %d incompatible with underlying device sector size %d\n", ssopt, sectsz); goto err; } @@ -709,7 +709,7 @@ blockif_open(const char *optstr, const char *ident) err_code = sub_file_validate(bc, fd, ro, bc->sub_file_start_lba, size); if (err_code < 0) { - fprintf(stderr, "subfile range specified not valid!\n"); + pr_err("subfile range specified not valid!\n"); exit(1); } DPRINTF(("Validated done!\n")); diff --git a/devicemodel/hw/pci/core.c b/devicemodel/hw/pci/core.c index bcfa7cd90..e81a35a01 100644 --- a/devicemodel/hw/pci/core.c +++ b/devicemodel/hw/pci/core.c @@ -159,7 +159,7 @@ is_pci_gvt(struct pci_vdev *dev) static void pci_parse_slot_usage(char *aopt) { - fprintf(stderr, "Invalid PCI slot info field \"%s\"\n", aopt); + pr_err("Invalid PCI slot info field \"%s\"\n", aopt); } int @@ -863,7 +863,7 @@ pci_emul_init(struct vmctx *ctx, struct pci_vdev_ops *ops, int bus, int slot, pdi = calloc(1, sizeof(struct pci_vdev)); if (!pdi) { - fprintf(stderr, "%s: calloc returns NULL\n", __func__); + pr_err("%s: calloc returns NULL\n", __func__); return -1; } @@ -2439,7 +2439,7 @@ pci_get_vdev_info(int slot) if (si != NULL) dev = si->si_funcs[0].fi_devi; else - fprintf(stderr, "slot=%d is empty!\n", slot); + pr_err("slot=%d is empty!\n", slot); return dev; } diff --git a/devicemodel/hw/pci/gvt.c b/devicemodel/hw/pci/gvt.c index 14063371e..ce61225ca 100644 --- a/devicemodel/hw/pci/gvt.c +++ b/devicemodel/hw/pci/gvt.c @@ -145,8 +145,7 @@ gvt_init_config(struct pci_gvt *gvt) ret = pci_emul_alloc_bar(gvt->gvt_pi, 0, PCIBAR_MEM32, 16 * 1024 * 1024); if (ret != 0) { - fprintf(stderr, - "allocate gvt pci bar[0] failed\n"); + pr_err("allocate gvt pci bar[0] failed\n"); return -1; } @@ -179,16 +178,14 @@ gvt_init_config(struct pci_gvt *gvt) ret = pci_emul_alloc_bar(gvt->gvt_pi, 2, PCIBAR_MEM32, aperture_size * 1024 * 1024); if (ret != 0) { - fprintf(stderr, - "allocate gvt pci bar[2] failed\n"); + pr_err("allocate gvt pci bar[2] failed\n"); return -1; } /* same as host, lagecy vga usage */ ret = pci_emul_alloc_bar(gvt->gvt_pi, 4, PCIBAR_IO, 64); if (ret != 0) { - fprintf(stderr, - "allocate gvt pci bar[4] failed\n"); + pr_err("allocate gvt pci bar[4] failed\n"); return -1; } diff --git a/devicemodel/hw/pci/lpc.c b/devicemodel/hw/pci/lpc.c index 46b074302..39a9d76f1 100644 --- a/devicemodel/hw/pci/lpc.c +++ b/devicemodel/hw/pci/lpc.c @@ -202,7 +202,7 @@ lpc_init(struct vmctx *ctx) if (uart_legacy_alloc(unit, &lpc_uart->iobase, &lpc_uart->irq) != 0) { - fprintf(stderr, "Unable to allocate resources for " + pr_err("Unable to allocate resources for " "LPC device %s\n", name); goto init_failed; } @@ -401,7 +401,7 @@ pci_lpc_init(struct vmctx *ctx, struct pci_vdev *pi, char *opts) * Do not allow more than one LPC bridge to be configured. */ if (lpc_bridge != NULL) { - fprintf(stderr, "Only one LPC bridge is allowed.\n"); + pr_err("Only one LPC bridge is allowed.\n"); return -1; } @@ -411,7 +411,7 @@ pci_lpc_init(struct vmctx *ctx, struct pci_vdev *pi, char *opts) * all legacy i/o ports behind bus 0. */ if (pi->bus != 0) { - fprintf(stderr, "LPC bridge can be present only on bus 0.\n"); + pr_err("LPC bridge can be present only on bus 0.\n"); return -1; } diff --git a/devicemodel/hw/pci/uart.c b/devicemodel/hw/pci/uart.c index a0eee6460..1a3104e8f 100644 --- a/devicemodel/hw/pci/uart.c +++ b/devicemodel/hw/pci/uart.c @@ -88,7 +88,7 @@ pci_uart_init(struct vmctx *ctx, struct pci_vdev *dev, char *opts) dev->arg = uart_set_backend(pci_uart_intr_assert, pci_uart_intr_deassert, dev, opts); if (dev->arg == NULL) { - fprintf(stderr, "Unable to initialize backend '%s' for " + pr_err("Unable to initialize backend '%s' for " "pci uart at %d:%d\n", opts, dev->slot, dev->func); return -1; } diff --git a/devicemodel/hw/pci/virtio/virtio.c b/devicemodel/hw/pci/virtio/virtio.c index 1e919f0c0..6a97928e8 100644 --- a/devicemodel/hw/pci/virtio/virtio.c +++ b/devicemodel/hw/pci/virtio/virtio.c @@ -64,7 +64,7 @@ virtio_start_timer(struct acrn_timer *timer, time_t sec, time_t nsec) ts.it_value.tv_sec = sec; ts.it_value.tv_nsec = nsec; if (acrn_timer_settime(timer, &ts) != 0) { - fprintf(stderr, "acrn timer set time failed\n"); + pr_err("acrn timer set time failed\n"); return; } } @@ -98,8 +98,7 @@ virtio_poll_timer(void *arg, uint64_t nexp) else if (vops->qnotify) (*vops->qnotify)(DEV_STRUCT(base), vq); else - fprintf(stderr, - "%s: qnotify queue %d: missing vq/vops notify\r\n", + pr_err("%s: qnotify queue %d: missing vq/vops notify\r\n", name, i); } @@ -131,8 +130,7 @@ virtio_linkup(struct virtio_base *base, struct virtio_ops *vops, /* base and pci_virtio_dev addresses must match */ if ((void *)base != pci_virtio_dev) { - fprintf(stderr, - "virtio_base and pci_virtio_dev addresses don't match!\n"); + pr_err("virtio_base and pci_virtio_dev addresses don't match!\n"); return; } base->vops = vops; @@ -461,8 +459,7 @@ vq_getchain(struct virtio_vq_info *vq, uint16_t *pidx, return 0; if (ndesc > vq->qsize) { /* XXX need better way to diagnose issues */ - fprintf(stderr, - "%s: ndesc (%u) out of range, driver confused?\r\n", + pr_err("%s: ndesc (%u) out of range, driver confused?\r\n", name, (u_int)ndesc); return -1; } @@ -480,8 +477,7 @@ vq_getchain(struct virtio_vq_info *vq, uint16_t *pidx, vq->last_avail++; for (i = 0; i < VQ_MAX_DESCRIPTORS; next = vdir->next) { if (next >= vq->qsize) { - fprintf(stderr, - "%s: descriptor index %u out of range, " + pr_err("%s: descriptor index %u out of range, " "driver confused?\r\n", name, next); return -1; @@ -492,16 +488,14 @@ vq_getchain(struct virtio_vq_info *vq, uint16_t *pidx, i++; } else if ((base->device_caps & (1 << VIRTIO_RING_F_INDIRECT_DESC)) == 0) { - fprintf(stderr, - "%s: descriptor has forbidden INDIRECT flag, " + pr_err("%s: descriptor has forbidden INDIRECT flag, " "driver confused?\r\n", name); return -1; } else { n_indir = vdir->len / 16; if ((vdir->len & 0xf) || n_indir == 0) { - fprintf(stderr, - "%s: invalid indir len 0x%x, " + pr_err("%s: invalid indir len 0x%x, " "driver confused?\r\n", name, (u_int)vdir->len); return -1; @@ -519,8 +513,7 @@ vq_getchain(struct virtio_vq_info *vq, uint16_t *pidx, for (;;) { vp = &vindir[next]; if (vp->flags & VRING_DESC_F_INDIRECT) { - fprintf(stderr, - "%s: indirect desc has INDIR flag," + pr_err("%s: indirect desc has INDIR flag," " driver confused?\r\n", name); return -1; @@ -532,8 +525,7 @@ vq_getchain(struct virtio_vq_info *vq, uint16_t *pidx, break; next = vp->next; if (next >= n_indir) { - fprintf(stderr, - "%s: invalid next %u > %u, " + pr_err("%s: invalid next %u > %u, " "driver confused?\r\n", name, (u_int)next, n_indir); return -1; @@ -544,8 +536,7 @@ vq_getchain(struct virtio_vq_info *vq, uint16_t *pidx, return i; } loopy: - fprintf(stderr, - "%s: descriptor loop? count > %d - driver confused?\r\n", + pr_err("%s: descriptor loop? count > %d - driver confused?\r\n", name, i); return -1; } @@ -811,12 +802,10 @@ bad: if (cr == NULL || cr->size != size) { if (cr != NULL) { /* offset must be OK, so size must be bad */ - fprintf(stderr, - "%s: read from %s: bad size %d\r\n", + pr_err("%s: read from %s: bad size %d\r\n", name, cr->name, size); } else { - fprintf(stderr, - "%s: read from bad offset/size %jd/%d\r\n", + pr_err("%s: read from bad offset/size %jd/%d\r\n", name, (uintmax_t)offset, size); } goto done; @@ -922,16 +911,13 @@ bad: if (cr != NULL) { /* offset must be OK, wrong size and/or reg is R/O */ if (cr->size != size) - fprintf(stderr, - "%s: write to %s: bad size %d\r\n", + pr_err("%s: write to %s: bad size %d\r\n", name, cr->name, size); if (cr->ro) - fprintf(stderr, - "%s: write to read-only reg %s\r\n", + pr_err("%s: write to read-only reg %s\r\n", name, cr->name); } else { - fprintf(stderr, - "%s: write to bad offset/size %jd/%d\r\n", + pr_err("%s: write to bad offset/size %jd/%d\r\n", name, (uintmax_t)offset, size); } goto done; @@ -959,7 +945,7 @@ bad: break; case VIRTIO_PCI_QUEUE_NOTIFY: if (value >= vops->nvq) { - fprintf(stderr, "%s: queue %d notify out of range\r\n", + pr_err("%s: queue %d notify out of range\r\n", name, (int)value); goto done; } @@ -969,8 +955,7 @@ bad: else if (vops->qnotify) (*vops->qnotify)(DEV_STRUCT(base), vq); else - fprintf(stderr, - "%s: qnotify queue %d: missing vq/vops notify\r\n", + pr_err("%s: qnotify queue %d: missing vq/vops notify\r\n", name, (int)value); break; case VIRTIO_PCI_STATUS: @@ -1004,8 +989,7 @@ bad: goto done; bad_qindex: - fprintf(stderr, - "%s: write config reg %s: curq %d >= max %d\r\n", + pr_err("%s: write config reg %s: curq %d >= max %d\r\n", name, cr->name, base->curq, vops->nvq); done: if (base->mtx) @@ -1065,8 +1049,7 @@ virtio_set_modern_mmio_bar(struct virtio_base *base, int barnum) vops = base->vops; if (vops->cfgsize > VIRTIO_CAP_DEVICE_SIZE) { - fprintf(stderr, - "%s: cfgsize %lu > max %d\r\n", + pr_err("%s: cfgsize %lu > max %d\r\n", vops->name, vops->cfgsize, VIRTIO_CAP_DEVICE_SIZE); return -1; } @@ -1077,8 +1060,7 @@ virtio_set_modern_mmio_bar(struct virtio_base *base, int barnum) cap.length = VIRTIO_CAP_COMMON_SIZE; rc = pci_emul_add_capability(base->dev, (u_char *)&cap, sizeof(cap)); if (rc != 0) { - fprintf(stderr, - "pci emulation add common configuration capability failed\n"); + pr_err("pci emulation add common configuration capability failed\n"); return -1; } @@ -1088,8 +1070,7 @@ virtio_set_modern_mmio_bar(struct virtio_base *base, int barnum) cap.length = VIRTIO_CAP_ISR_SIZE; rc = pci_emul_add_capability(base->dev, (u_char *)&cap, sizeof(cap)); if (rc != 0) { - fprintf(stderr, - "pci emulation add isr status capability failed\n"); + pr_err("pci emulation add isr status capability failed\n"); return -1; } @@ -1099,8 +1080,7 @@ virtio_set_modern_mmio_bar(struct virtio_base *base, int barnum) cap.length = VIRTIO_CAP_DEVICE_SIZE; rc = pci_emul_add_capability(base->dev, (u_char *)&cap, sizeof(cap)); if (rc != 0) { - fprintf(stderr, - "pci emulation add device specific configuration capability failed\n"); + pr_err("pci emulation add device specific configuration capability failed\n"); return -1; } @@ -1108,16 +1088,14 @@ virtio_set_modern_mmio_bar(struct virtio_base *base, int barnum) rc = pci_emul_add_capability(base->dev, (u_char *)¬ify, sizeof(notify)); if (rc != 0) { - fprintf(stderr, - "pci emulation add notification capability failed\n"); + pr_err("pci emulation add notification capability failed\n"); return -1; } /* pci alternative configuration access capability */ rc = pci_emul_add_capability(base->dev, (u_char *)&cfg, sizeof(cfg)); if (rc != 0) { - fprintf(stderr, - "pci emulation add alternative configuration access capability failed\n"); + pr_err("pci emulation add alternative configuration access capability failed\n"); return -1; } @@ -1125,15 +1103,13 @@ virtio_set_modern_mmio_bar(struct virtio_base *base, int barnum) rc = pci_emul_alloc_bar(base->dev, barnum, PCIBAR_MEM64, VIRTIO_MODERN_MEM_BAR_SIZE); if (rc != 0) { - fprintf(stderr, - "allocate and register modern memory bar failed\n"); + pr_err("allocate and register modern memory bar failed\n"); return -1; } base->cfg_coff = virtio_find_capability(base, VIRTIO_PCI_CAP_PCI_CFG); if (base->cfg_coff < 0) { - fprintf(stderr, - "%s: VIRTIO_PCI_CAP_PCI_CFG not found\r\n", + pr_err("%s: VIRTIO_PCI_CAP_PCI_CFG not found\r\n", vops->name); return -1; } @@ -1164,16 +1140,14 @@ virtio_set_modern_pio_bar(struct virtio_base *base, int barnum) rc = pci_emul_add_capability(base->dev, (u_char *)¬ify_pio, sizeof(notify_pio)); if (rc != 0) { - fprintf(stderr, - "pci emulation add notification capability for virtio modern PIO BAR failed\n"); + pr_err("pci emulation add notification capability for virtio modern PIO BAR failed\n"); return -1; } /* allocate and register modern pio bar */ rc = pci_emul_alloc_bar(base->dev, barnum, PCIBAR_IO, 4); if (rc != 0) { - fprintf(stderr, - "allocate and register modern pio bar failed\n"); + pr_err("allocate and register modern pio bar failed\n"); return -1; } @@ -1261,12 +1235,10 @@ virtio_common_cfg_read(struct pci_vdev *dev, uint64_t offset, int size) if (cr == NULL || cr->size != size) { if (cr != NULL) { /* offset must be OK, so size must be bad */ - fprintf(stderr, - "%s: read from %s: bad size %d\r\n", + pr_err("%s: read from %s: bad size %d\r\n", name, cr->name, size); } else { - fprintf(stderr, - "%s: read from bad offset/size %jd/%d\r\n", + pr_err("%s: read from bad offset/size %jd/%d\r\n", name, (uintmax_t)offset, size); } @@ -1378,16 +1350,13 @@ virtio_common_cfg_write(struct pci_vdev *dev, uint64_t offset, int size, if (cr != NULL) { /* offset must be OK, wrong size and/or reg is R/O */ if (cr->size != size) - fprintf(stderr, - "%s: write to %s: bad size %d\r\n", + pr_err("%s: write to %s: bad size %d\r\n", name, cr->name, size); if (cr->ro) - fprintf(stderr, - "%s: write to read-only reg %s\r\n", + pr_err("%s: write to read-only reg %s\r\n", name, cr->name); } else { - fprintf(stderr, - "%s: write to bad offset/size %jd/%d\r\n", + pr_err("%s: write to bad offset/size %jd/%d\r\n", name, (uintmax_t)offset, size); } @@ -1491,8 +1460,7 @@ virtio_common_cfg_write(struct pci_vdev *dev, uint64_t offset, int size, return; bad_qindex: - fprintf(stderr, - "%s: write config reg %s: curq %d >= max %d\r\n", + pr_err("%s: write config reg %s: curq %d >= max %d\r\n", name, cr->name, base->curq, vops->nvq); } @@ -1527,16 +1495,14 @@ virtio_device_cfg_read(struct pci_vdev *dev, uint64_t offset, int size) max = vops->cfgsize ? vops->cfgsize : 0x100000000; if (offset + size > max) { - fprintf(stderr, - "%s: reading from 0x%lx size %d exceeds limit\r\n", + pr_err("%s: reading from 0x%lx size %d exceeds limit\r\n", name, offset, size); return value; } error = (*vops->cfgread)(DEV_STRUCT(base), offset, size, &value); if (error) { - fprintf(stderr, - "%s: reading from 0x%lx size %d failed %d\r\n", + pr_err("%s: reading from 0x%lx size %d failed %d\r\n", name, offset, size, error); value = size == 1 ? 0xff : size == 2 ? 0xffff : 0xffffffff; } @@ -1559,16 +1525,14 @@ virtio_device_cfg_write(struct pci_vdev *dev, uint64_t offset, int size, max = vops->cfgsize ? vops->cfgsize : 0x100000000; if (offset + size > max) { - fprintf(stderr, - "%s: writing to 0x%lx size %d exceeds limit\r\n", + pr_err("%s: writing to 0x%lx size %d exceeds limit\r\n", name, offset, size); return; } error = (*vops->cfgwrite)(DEV_STRUCT(base), offset, size, value); if (error) - fprintf(stderr, - "%s: writing ot 0x%lx size %d failed %d\r\n", + pr_err("%s: writing ot 0x%lx size %d failed %d\r\n", name, offset, size, error); } @@ -1591,8 +1555,7 @@ virtio_notify_cfg_write(struct pci_vdev *dev, uint64_t offset, int size, name = vops->name; if (idx >= vops->nvq) { - fprintf(stderr, - "%s: queue %lu notify out of range\r\n", name, idx); + pr_err("%s: queue %lu notify out of range\r\n", name, idx); return; } @@ -1602,8 +1565,7 @@ virtio_notify_cfg_write(struct pci_vdev *dev, uint64_t offset, int size, else if (vops->qnotify) (*vops->qnotify)(DEV_STRUCT(base), vq); else - fprintf(stderr, - "%s: qnotify queue %lu: missing vq/vops notify\r\n", + pr_err("%s: qnotify queue %lu: missing vq/vops notify\r\n", name, idx); } @@ -1623,16 +1585,14 @@ virtio_pci_modern_mmio_read(struct vmctx *ctx, int vcpu, struct pci_vdev *dev, value = size == 1 ? 0xff : size == 2 ? 0xffff : 0xffffffff; if (size != 1 && size != 2 && size != 4) { - fprintf(stderr, - "%s: read from [%d:0x%lx] bad size %d\r\n", + pr_err("%s: read from [%d:0x%lx] bad size %d\r\n", name, baridx, offset, size); return value; } capid = virtio_get_cap_id(offset, size); if (capid < 0) { - fprintf(stderr, - "%s: read from [%d:0x%lx] bad range %d\r\n", + pr_err("%s: read from [%d:0x%lx] bad range %d\r\n", name, baridx, offset, size); return value; } @@ -1654,8 +1614,7 @@ virtio_pci_modern_mmio_read(struct vmctx *ctx, int vcpu, struct pci_vdev *dev, value = virtio_device_cfg_read(dev, offset, size); break; default: /* guest driver should not read from notify region */ - fprintf(stderr, - "%s: read from [%d:0x%lx] size %d not supported\r\n", + pr_err("%s: read from [%d:0x%lx] size %d not supported\r\n", name, baridx, offset, size); } @@ -1679,16 +1638,14 @@ virtio_pci_modern_mmio_write(struct vmctx *ctx, int vcpu, struct pci_vdev *dev, name = vops->name; if (size != 1 && size != 2 && size != 4) { - fprintf(stderr, - "%s: write to [%d:0x%lx] bad size %d\r\n", + pr_err("%s: write to [%d:0x%lx] bad size %d\r\n", name, baridx, offset, size); return; } capid = virtio_get_cap_id(offset, size); if (capid < 0) { - fprintf(stderr, - "%s: write to [%d:0x%lx] bad range %d\r\n", + pr_err("%s: write to [%d:0x%lx] bad range %d\r\n", name, baridx, offset, size); return; } @@ -1710,8 +1667,7 @@ virtio_pci_modern_mmio_write(struct vmctx *ctx, int vcpu, struct pci_vdev *dev, virtio_notify_cfg_write(dev, offset, size, value); break; default: /* guest driver should not write to ISR region */ - fprintf(stderr, - "%s: write to [%d:0x%lx] size %d not supported\r\n", + pr_err("%s: write to [%d:0x%lx] size %d not supported\r\n", name, baridx, offset, size); } @@ -1744,15 +1700,13 @@ virtio_pci_modern_pio_write(struct vmctx *ctx, int vcpu, struct pci_vdev *dev, idx = value; if (size != 1 && size != 2 && size != 4) { - fprintf(stderr, - "%s: write to [%d:0x%lx] bad size %d\r\n", + pr_err("%s: write to [%d:0x%lx] bad size %d\r\n", name, baridx, offset, size); return; } if (idx >= vops->nvq) { - fprintf(stderr, - "%s: queue %lu notify out of range\r\n", name, idx); + pr_err("%s: queue %lu notify out of range\r\n", name, idx); return; } @@ -1765,8 +1719,7 @@ virtio_pci_modern_pio_write(struct vmctx *ctx, int vcpu, struct pci_vdev *dev, else if (vops->qnotify) (*vops->qnotify)(DEV_STRUCT(base), vq); else - fprintf(stderr, - "%s: qnotify queue %lu: missing vq/vops notify\r\n", + pr_err("%s: qnotify queue %lu: missing vq/vops notify\r\n", name, idx); if (base->mtx) @@ -1813,7 +1766,7 @@ virtio_pci_read(struct vmctx *ctx, int vcpu, struct pci_vdev *dev, return virtio_pci_modern_pio_read(ctx, vcpu, dev, baridx, offset, size); - fprintf(stderr, "%s: read unexpected baridx %d\r\n", + pr_err("%s: read unexpected baridx %d\r\n", base->vops->name, baridx); return size == 1 ? 0xff : size == 2 ? 0xffff : 0xffffffff; } @@ -1866,7 +1819,7 @@ virtio_pci_write(struct vmctx *ctx, int vcpu, struct pci_vdev *dev, return; } - fprintf(stderr, "%s: write unexpected baridx %d\r\n", + pr_err("%s: write unexpected baridx %d\r\n", base->vops->name, baridx); } diff --git a/devicemodel/hw/pci/virtio/virtio_block.c b/devicemodel/hw/pci/virtio/virtio_block.c index 6d02abdab..5d155b3ac 100644 --- a/devicemodel/hw/pci/virtio/virtio_block.c +++ b/devicemodel/hw/pci/virtio/virtio_block.c @@ -565,7 +565,7 @@ virtio_blk_init(struct vmctx *ctx, struct pci_vdev *dev, char *opts) register_vm_monitor_blkrescan = true; if (monitor_register_vm_ops(&virtio_blk_rescan_ops, ctx, "virtio_blk_rescan") < 0) - fprintf(stderr, "Rescan registration to VM monitor failed\n"); + pr_err("Rescan registration to VM monitor failed\n"); } return 0; @@ -654,24 +654,24 @@ virtio_blk_rescan(struct vmctx *ctx, struct pci_vdev *dev, char *newpath) struct virtio_blk *blk = (struct virtio_blk *) dev->arg; if (!blk) { - fprintf(stderr, "Invalid virtio_blk device!\n"); + pr_err("Invalid virtio_blk device!\n"); goto end; } /* validate inputs for virtio-blk blockrescan */ if (newpath == NULL) { - fprintf(stderr, "no path info available\n"); + pr_err("no path info available\n"); goto end; } if (strstr(newpath, "nodisk") != NULL) { - fprintf(stderr, "no valid backend file found\n"); + pr_err("no valid backend file found\n"); goto end; } if (snprintf(bident, sizeof(bident), "%d:%d", dev->slot, dev->func) >= sizeof(bident)) { - fprintf(stderr, "bident error, please check slot and func\n"); + pr_err("bident error, please check slot and func\n"); goto end; } @@ -680,15 +680,15 @@ virtio_blk_rescan(struct vmctx *ctx, struct pci_vdev *dev, char *newpath) * If this is the case, blk->bc would be null. */ if (blk->bc) { - fprintf(stderr, "Replacing valid backend file not supported!\n"); + pr_err("Replacing valid backend file not supported!\n"); goto end; } - fprintf(stderr, "name=%s, Path=%s, ident=%s\n", dev->name, newpath, bident); + pr_err("name=%s, Path=%s, ident=%s\n", dev->name, newpath, bident); /* update the bctxt for the virtio-blk device */ bctxt = blockif_open(newpath, bident); if (bctxt == NULL) { - fprintf(stderr, "Error opening backing file\n"); + pr_err("Error opening backing file\n"); goto end; } @@ -725,30 +725,30 @@ vm_monitor_blkrescan(void *arg, char *devargs) if ((str_slot != NULL) && (str_newpath != NULL)) { error = dm_strtoi(str_slot, &str_slot, 10, &slot); if (error) { - fprintf(stderr, "Incorrect slot, error=0x%x!\n", error); + pr_err("Incorrect slot, error=0x%x!\n", error); goto end; } } else { - fprintf(stderr, "Slot info or path not available!"); + pr_err("Slot info or path not available!"); error = -1; goto end; } dev = pci_get_vdev_info(slot); if (dev == NULL) { - fprintf(stderr, "vdev info failed for Slot %d\n!", slot); + pr_err("vdev info failed for Slot %d\n!", slot); error = -1; goto end; } if (strstr(dev->name, "virtio-blk") == NULL) { error = -1; - fprintf(stderr, "virtio-blk only supports rescan: found %s at slot %d\n", dev->name, slot); + pr_err("virtio-blk only supports rescan: found %s at slot %d\n", dev->name, slot); } else { error = virtio_blk_rescan(ctx, dev, str_newpath); if (error) { - fprintf(stderr, "virtio-blk rescan failed!"); + pr_err("virtio-blk rescan failed!"); } } end: diff --git a/devicemodel/hw/pci/virtio/virtio_net.c b/devicemodel/hw/pci/virtio/virtio_net.c index a61a10af7..6d51eea18 100644 --- a/devicemodel/hw/pci/virtio/virtio_net.c +++ b/devicemodel/hw/pci/virtio/virtio_net.c @@ -639,7 +639,7 @@ virtio_net_parsemac(char *mac_str, uint8_t *mac_addr) if (ea == NULL || ETHER_IS_MULTICAST(ea->ether_addr_octet) || memcmp(ea->ether_addr_octet, zero_addr, ETHER_ADDR_LEN) == 0) { - fprintf(stderr, "Invalid MAC %s\n", mac_str); + pr_err("Invalid MAC %s\n", mac_str); return -1; } memcpy(mac_addr, ea->ether_addr_octet, ETHER_ADDR_LEN); @@ -998,7 +998,7 @@ virtio_net_teardown(void *param) close(net->tapfd); net->tapfd = -1; } else - fprintf(stderr, "net->tapfd is -1!\n"); + pr_err("net->tapfd is -1!\n"); free(net); } @@ -1027,7 +1027,7 @@ virtio_net_deinit(struct vmctx *ctx, struct pci_vdev *dev, char *opts) DPRINTF(("%s: done\n", __func__)); } else - fprintf(stderr, "%s: NULL!\n", __func__); + pr_err("%s: NULL!\n", __func__); } static struct vhost_net * diff --git a/devicemodel/hw/platform/acpi/acpi.c b/devicemodel/hw/platform/acpi/acpi.c index 44d433a16..3d815975b 100644 --- a/devicemodel/hw/platform/acpi/acpi.c +++ b/devicemodel/hw/platform/acpi/acpi.c @@ -68,6 +68,7 @@ #include "tpm.h" #include "vmmapi.h" #include "hpet.h" +#include "log.h" /* * Define the base address of the ACPI tables, and the offsets to @@ -623,7 +624,7 @@ basl_fwrite_nhlt(FILE *fp, struct vmctx *ctx) int fd = open("/sys/firmware/acpi/tables/NHLT", O_RDONLY); if (fd < 0) { - fprintf(stderr, "Open host NHLT fail! %s\n", strerror(errno)); + pr_err("Open host NHLT fail! %s\n", strerror(errno)); return -1; } @@ -631,7 +632,7 @@ basl_fwrite_nhlt(FILE *fp, struct vmctx *ctx) audio_nhlt_len = lseek(fd, 0, SEEK_END); /* check if file size exceeds reserved room */ if (audio_nhlt_len > DSDT_OFFSET - NHLT_OFFSET) { - fprintf(stderr, "Host NHLT exceeds reserved room!\n"); + pr_err("Host NHLT exceeds reserved room!\n"); close(fd); return -1; } @@ -639,7 +640,7 @@ basl_fwrite_nhlt(FILE *fp, struct vmctx *ctx) /* skip 36 bytes as NHLT table header */ offset = lseek(fd, 36, SEEK_SET); if (offset != 36) { - fprintf(stderr, "Seek NHLT data fail! %s\n", strerror(errno)); + pr_err("Seek NHLT data fail! %s\n", strerror(errno)); close(fd); return -1; } @@ -663,7 +664,7 @@ basl_fwrite_nhlt(FILE *fp, struct vmctx *ctx) EFPRINTF(fp, "UINT8 : %02X\n", data); if (len < 0) { - fprintf(stderr, "Read host NHLT fail! %s\n", strerror(errno)); + pr_err("Read host NHLT fail! %s\n", strerror(errno)); close(fd); return -1; } @@ -690,7 +691,7 @@ copy_table_pos_len(int fd, int offset, int len, FILE *fp) for (i = 0; i < len; i++) { if (read(fd, &data, 1) != 1) { - fprintf(stderr, "%s: read fail! %s\n", __func__, strerror(errno)); + pr_err("%s: read fail! %s\n", __func__, strerror(errno)); return -1; } EFPRINTF(fp, "UINT8 : %02X\n", data); @@ -739,7 +740,7 @@ basl_fwrite_psds(FILE *fp, struct vmctx *ctx) * [0004]PSD Version */ if (copy_table_pos_len(psds_fd, 36, 4, fp) != 0) { - fprintf(stderr, "Failed to read psds table!\n"); + pr_err("Failed to read psds table!\n"); return -1; } @@ -752,7 +753,7 @@ basl_fwrite_psds(FILE *fp, struct vmctx *ctx) * [0001]EOM State */ if (copy_table_pos_len(psds_fd, 46, 33, fp) !=0) { - fprintf(stderr, "Failed to read psds table!\n"); + pr_err("Failed to read psds table!\n"); return -1; } @@ -1169,7 +1170,7 @@ void acpi_table_enable(int num) { if (num > (ARRAY_SIZE(basl_ftables) - 1)) { - fprintf(stderr, "Enable non-existing ACPI tables:%d\n", num); + pr_err("Enable non-existing ACPI tables:%d\n", num); return; } diff --git a/devicemodel/hw/platform/ps2kbd.c b/devicemodel/hw/platform/ps2kbd.c index d02d72b93..bc5b925f3 100644 --- a/devicemodel/hw/platform/ps2kbd.c +++ b/devicemodel/hw/platform/ps2kbd.c @@ -145,7 +145,7 @@ ps2kbd_write(struct ps2kbd_info *kbd, uint8_t val) fifo_put(kbd, PS2KC_ACK); break; default: - fprintf(stderr, "Unhandled ps2 keyboard current " + pr_err("Unhandled ps2 keyboard current " "command byte 0x%02x\n", val); break; } @@ -190,7 +190,7 @@ ps2kbd_write(struct ps2kbd_info *kbd, uint8_t val) fifo_put(kbd, PS2KC_ACK); break; default: - fprintf(stderr, "Unhandled ps2 keyboard command " + pr_err("Unhandled ps2 keyboard command " "0x%02x\n", val); break; } @@ -429,7 +429,7 @@ ps2kbd_keysym_queue(struct ps2kbd_info *kbd, fifo_put(kbd, 0x71); break; default: - fprintf(stderr, "Unhandled ps2 keyboard keysym 0x%x\n", + pr_err("Unhandled ps2 keyboard keysym 0x%x\n", keysym); break; } diff --git a/devicemodel/hw/platform/ps2mouse.c b/devicemodel/hw/platform/ps2mouse.c index 3cf5cf0c5..bde35ace8 100644 --- a/devicemodel/hw/platform/ps2mouse.c +++ b/devicemodel/hw/platform/ps2mouse.c @@ -277,7 +277,7 @@ ps2mouse_write(struct ps2mouse_info *mouse, uint8_t val, int insert) fifo_put(mouse, PS2MC_ACK); break; default: - fprintf(stderr, "Unhandled ps2 mouse current " + pr_err("Unhandled ps2 mouse current " "command byte 0x%02x\n", val); break; } @@ -346,7 +346,7 @@ ps2mouse_write(struct ps2mouse_info *mouse, uint8_t val, int insert) break; default: fifo_put(mouse, PS2MC_ACK); - fprintf(stderr, "Unhandled ps2 mouse command " + pr_err("Unhandled ps2 mouse command " "0x%02x\n", val); break; } diff --git a/devicemodel/hw/platform/rpmb/att_keybox.c b/devicemodel/hw/platform/rpmb/att_keybox.c index bbbb69084..4168bf34f 100644 --- a/devicemodel/hw/platform/rpmb/att_keybox.c +++ b/devicemodel/hw/platform/rpmb/att_keybox.c @@ -36,6 +36,7 @@ #include #include #include "att_keybox.h" +#include "log.h" static const uuid_le HECI_CLIENT_GUID = UUID_LE(0x8e6a6715, 0x9abc, 0x4043, @@ -55,7 +56,7 @@ uint16_t get_attkb_size(void) fd = open(MEI_DEV, O_RDWR); if (fd == -1) { - fprintf(stderr, "Failed to open %s, %s\n", + pr_err("Failed to open %s, %s\n", MEI_DEV, strerror(errno)); return 0; } @@ -65,7 +66,7 @@ uint16_t get_attkb_size(void) ret = ioctl(fd, IOCTL_MEI_CONNECT_CLIENT, &mdcd); if (ret) { - fprintf(stderr, "HECI connection failed, %s\n", + pr_err("HECI connection failed, %s\n", strerror(errno)); goto err; } @@ -80,26 +81,26 @@ uint16_t get_attkb_size(void) ret = write(fd, &req, sizeof(req)); if (ret != sizeof(req)) { - fprintf(stderr, "Failed to send HECI command, %s\n", + pr_err("Failed to send HECI command, %s\n", strerror(errno)); goto err; } ret = read(fd, &resp, sizeof(resp)); if (ret != sizeof(resp)) { - fprintf(stderr, "ret = %d,Failed to read HECI command result, %d:%s\n", + pr_err("ret = %d,Failed to read HECI command result, %d:%s\n", ret, errno, strerror(errno)); goto err; } if ((resp.header.is_response != 1) || (resp.header.result != 0)) { - fprintf(stderr, "Failed to check resp header = 0x%x\n", + pr_err("Failed to check resp header = 0x%x\n", resp.header.result); goto err; } if (resp.total_file_size == 0) { - fprintf(stderr, "ret = %d, Unexpected filesize 0!\n", ret); + pr_err("ret = %d, Unexpected filesize 0!\n", ret); } close(fd); @@ -127,7 +128,7 @@ uint16_t read_attkb(void *data, uint16_t size) fd = open(MEI_DEV, O_RDWR); if (fd == -1) { - fprintf(stderr, "Failed to open %s, %s\n", + pr_err("Failed to open %s, %s\n", MEI_DEV, strerror(errno)); return 0; } @@ -137,7 +138,7 @@ uint16_t read_attkb(void *data, uint16_t size) ret = ioctl(fd, IOCTL_MEI_CONNECT_CLIENT, &mdcd); if (ret) { - fprintf(stderr, "HECI connection failed, %s\n", + pr_err("HECI connection failed, %s\n", strerror(errno)); goto err; } @@ -157,27 +158,27 @@ uint16_t read_attkb(void *data, uint16_t size) ret = write(fd, &req, sizeof(req)); if (ret != sizeof(req)) { - fprintf(stderr, "Failed to send HECI command, %s\n", + pr_err("Failed to send HECI command, %s\n", strerror(errno)); goto err; } ret = read(fd, &resp, sizeof(resp)); if (ret != sizeof(resp)) { - fprintf(stderr, "Failed to read HECI command result, %s\n", + pr_err("Failed to read HECI command result, %s\n", strerror(errno)); goto err; } if ((resp.header.is_response != 1) || (resp.header.result != 0)) { - fprintf(stderr, "Failed to check resp header = 0x%x\n", + pr_err("Failed to check resp header = 0x%x\n", resp.header.result); goto err; } ret = read(fd, (uint8_t *)data + bytes_read, req.size); if (ret != req.size) { - fprintf(stderr, "Failed to read attkb, %s\n", + pr_err("Failed to read attkb, %s\n", strerror(errno)); goto err; } diff --git a/devicemodel/hw/platform/tpm/tpm_emulator.c b/devicemodel/hw/platform/tpm/tpm_emulator.c index a946fcba4..9e279d837 100644 --- a/devicemodel/hw/platform/tpm/tpm_emulator.c +++ b/devicemodel/hw/platform/tpm/tpm_emulator.c @@ -292,7 +292,7 @@ static int ctrl_chan_write(int ctrl_chan_fd, const uint8_t *buf, int len, } while (ret < 0 && errno == EINTR); if (ret < 0) { - fprintf(stderr, "Failed to send msg, reason: %s\n", strerror(errno)); + pr_err("Failed to send msg, reason: %s\n", strerror(errno)); } return ret; @@ -350,7 +350,7 @@ static int cmd_chan_write(int cmd_chan_fd, const uint8_t *buf, int len) buf += nwritten; } else { - fprintf(stderr, "cmd_chan_write: Error, write() %d %s\n", + pr_err("cmd_chan_write: Error, write() %d %s\n", errno, strerror(errno)); return -1; } @@ -376,12 +376,12 @@ static int cmd_chan_read(int cmd_chan_fd, uint8_t *buf, int len) buf += nread; } else if (nread < 0) {/* error */ - fprintf(stderr, "cmd_chan_read: Error, read() error %d %s\n", + pr_err("cmd_chan_read: Error, read() error %d %s\n", errno, strerror(errno)); return -1; } else if (nread == 0) {/* EOF */ - fprintf(stderr, "cmd_chan_read: Error, read EOF, read %lu bytes\n", + pr_err("cmd_chan_read: Error, read EOF, read %lu bytes\n", (unsigned long)(len - nleft)); return -1; }