Lines Matching refs:g
70 static void flush_maps(kdd_guest *g) in flush_maps() argument
74 if (g->maps[i] != NULL) in flush_maps()
75 munmap(g->maps[i], PAGE_SIZE); in flush_maps()
76 g->maps[i] = NULL; in flush_maps()
82 void kdd_halt(kdd_guest *g) in kdd_halt() argument
87 xc_domain_pause(g->xc_handle, g->domid); in kdd_halt()
90 sz = xc_domain_hvm_getcontext(g->xc_handle, g->domid, 0, 0); in kdd_halt()
92 KDD_LOG(g, "Can't get HVM state size for domid %"PRIu32": %s\n", in kdd_halt()
93 g->domid, strerror(errno)); in kdd_halt()
96 buf = realloc(g->hvm_buf, sz); in kdd_halt()
98 KDD_LOG(g, "Couldn't allocate %"PRIu32" for HVM buffer\n", sz); in kdd_halt()
101 g->hvm_buf = buf; in kdd_halt()
102 g->hvm_sz = sz; in kdd_halt()
106 sz = xc_domain_hvm_getcontext(g->xc_handle, g->domid, buf, sz); in kdd_halt()
108 KDD_LOG(g, "Can't get HVM state for domid %"PRIu32": %s\n", in kdd_halt()
109 g->domid, strerror(errno)); in kdd_halt()
116 int kdd_poll_guest(kdd_guest *g) in kdd_poll_guest() argument
123 static void hvm_writeback(kdd_guest *g) in hvm_writeback() argument
125 if (g->hvm_buf && xc_domain_hvm_setcontext(g->xc_handle, g->domid, in hvm_writeback()
126 g->hvm_buf, g->hvm_sz)) in hvm_writeback()
127 KDD_LOG(g, "Can't set HVM state for domid %"PRIu32": %s\n", in hvm_writeback()
128 g->domid, strerror(errno)); in hvm_writeback()
132 void kdd_run(kdd_guest *g) in kdd_run() argument
134 flush_maps(g); in kdd_run()
135 hvm_writeback(g); in kdd_run()
136 xc_domain_unpause(g->xc_handle, g->domid); in kdd_run()
140 int kdd_count_cpus(kdd_guest *g) in kdd_count_cpus() argument
145 if (!g->hvm_buf) in kdd_count_cpus()
149 for (desc = g->hvm_buf; in kdd_count_cpus()
150 (void *) desc >= g->hvm_buf && (void *) desc < g->hvm_buf + g->hvm_sz; in kdd_count_cpus()
161 static struct hvm_hw_cpu *get_cpu(kdd_guest *g, int cpuid) in get_cpu() argument
166 if (!g->hvm_buf) in get_cpu()
170 for (desc = g->hvm_buf; in get_cpu()
171 (void *) desc >= g->hvm_buf && (void *) desc < g->hvm_buf + g->hvm_sz; in get_cpu()
175 if ((void *) cpu + sizeof (*cpu) <= g->hvm_buf + g->hvm_sz) in get_cpu()
180 KDD_LOG(g, "Dom %"PRIu32" has no CPU %i\n", g->domid, cpuid); in get_cpu()
185 static struct hvm_hw_lapic_regs *get_lapic(kdd_guest *g, int cpuid) in get_lapic() argument
190 if (!g->hvm_buf) in get_lapic()
194 for (desc = g->hvm_buf; in get_lapic()
195 (void *) desc >= g->hvm_buf && (void *) desc < g->hvm_buf + g->hvm_sz; in get_lapic()
199 if ((void *) regs + sizeof (*regs) <= g->hvm_buf + g->hvm_sz) in get_lapic()
204 KDD_LOG(g, "Dom %"PRIu32" has no LAPIC %i\n", g->domid, cpuid); in get_lapic()
328 int kdd_get_regs(kdd_guest *g, int cpuid, kdd_regs *r, int w64) in kdd_get_regs() argument
332 cpu = get_cpu(g, cpuid); in kdd_get_regs()
346 int kdd_set_regs(kdd_guest *g, int cpuid, kdd_regs *r, int w64) in kdd_set_regs() argument
350 cpu = get_cpu(g, cpuid); in kdd_set_regs()
359 hvm_writeback(g); in kdd_set_regs()
409 int kdd_get_ctrl(kdd_guest *g, int cpuid, kdd_ctrl *ctrl, int w64) in kdd_get_ctrl() argument
414 cpu = get_cpu(g, cpuid); in kdd_get_ctrl()
419 lapic = get_lapic(g, cpuid); in kdd_get_ctrl()
430 int kdd_wrmsr(kdd_guest *g, int cpuid, uint32_t msr, uint64_t value) in kdd_wrmsr() argument
434 cpu = get_cpu(g, cpuid); in kdd_wrmsr()
454 hvm_writeback(g); in kdd_wrmsr()
458 int kdd_rdmsr(kdd_guest *g, int cpuid, uint32_t msr, uint64_t *value) in kdd_rdmsr() argument
462 cpu = get_cpu(g, cpuid); in kdd_rdmsr()
487 static uint32_t kdd_access_physical_page(kdd_guest *g, uint64_t addr, in kdd_access_physical_page() argument
497 if (g->pfns[map_pfn % MAPSIZE] != map_pfn in kdd_access_physical_page()
498 && g->maps[map_pfn % MAPSIZE] != NULL) { in kdd_access_physical_page()
499 munmap(g->maps[map_pfn % MAPSIZE], PAGE_SIZE); in kdd_access_physical_page()
500 g->maps[map_pfn % MAPSIZE] = NULL; in kdd_access_physical_page()
502 g->pfns[map_pfn % MAPSIZE] = map_pfn; in kdd_access_physical_page()
505 if (g->maps[map_pfn % MAPSIZE] != NULL) in kdd_access_physical_page()
506 map = g->maps[map_pfn % MAPSIZE]; in kdd_access_physical_page()
508 map = xc_map_foreign_range(g->xc_handle, in kdd_access_physical_page()
509 g->domid, in kdd_access_physical_page()
514 KDD_DEBUG(g, "map: %u, 0x%16.16"PRIx32": %p +0x%"PRIx32"\n", in kdd_access_physical_page()
520 g->maps[map_pfn % MAPSIZE] = map; in kdd_access_physical_page()
531 uint32_t kdd_access_physical(kdd_guest *g, uint64_t addr, in kdd_access_physical() argument
539 rv = kdd_access_physical_page(g, addr, chunk, buf, write); in kdd_access_physical()
559 kdd_guest *g = (kdd_guest *) logger; in kdd_xc_log() local
561 if (g->verbosity < 1 || (level < XTL_WARN && g->verbosity < 3)) in kdd_xc_log()
563 fprintf(g->log, "libxc[%s:%i:%i]: ", context ? : "?", level, errnoval); in kdd_xc_log()
564 vfprintf(g->log, format, al); in kdd_xc_log()
565 fprintf(g->log, "\n"); in kdd_xc_log()
566 (void) fflush(g->log); in kdd_xc_log()
573 kdd_guest *g = NULL; in kdd_guest_init() local
578 g = calloc(1, sizeof (kdd_guest)); in kdd_guest_init()
579 if (!g) in kdd_guest_init()
581 g->log = log; in kdd_guest_init()
582 g->verbosity = verbosity; in kdd_guest_init()
583 g->xc_log.vmessage = kdd_xc_log; in kdd_guest_init()
585 xch = xc_interface_open(&g->xc_log, NULL, 0); in kdd_guest_init()
588 g->xc_handle = xch; in kdd_guest_init()
593 g->domid = domid; in kdd_guest_init()
599 snprintf(g->id, (sizeof g->id) - 1, in kdd_guest_init()
600 "a xen guest with domain id %i", g->domid); in kdd_guest_init()
602 return g; in kdd_guest_init()
605 free(g); in kdd_guest_init()
612 char *kdd_guest_identify(kdd_guest *g) in kdd_guest_identify() argument
614 return g->id; in kdd_guest_identify()
618 void kdd_guest_teardown(kdd_guest *g) in kdd_guest_teardown() argument
620 flush_maps(g); in kdd_guest_teardown()
621 xc_interface_close(g->xc_handle); in kdd_guest_teardown()
622 free(g->hvm_buf); in kdd_guest_teardown()
623 free(g); in kdd_guest_teardown()