api.c 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684
  1. /*
  2. * QEMU Plugin API
  3. *
  4. * This provides the API that is available to the plugins to interact
  5. * with QEMU. We have to be careful not to expose internal details of
  6. * how QEMU works so we abstract out things like translation and
  7. * instructions to anonymous data types:
  8. *
  9. * qemu_plugin_tb
  10. * qemu_plugin_insn
  11. * qemu_plugin_register
  12. *
  13. * Which can then be passed back into the API to do additional things.
  14. * As such all the public functions in here are exported in
  15. * qemu-plugin.h.
  16. *
  17. * The general life-cycle of a plugin is:
  18. *
  19. * - plugin is loaded, public qemu_plugin_install called
  20. * - the install func registers callbacks for events
  21. * - usually an atexit_cb is registered to dump info at the end
  22. * - when a registered event occurs the plugin is called
  23. * - some events pass additional info
  24. * - during translation the plugin can decide to instrument any
  25. * instruction
  26. * - when QEMU exits all the registered atexit callbacks are called
  27. *
  28. * Copyright (C) 2017, Emilio G. Cota <cota@braap.org>
  29. * Copyright (C) 2019, Linaro
  30. *
  31. * License: GNU GPL, version 2 or later.
  32. * See the COPYING file in the top-level directory.
  33. *
  34. * SPDX-License-Identifier: GPL-2.0-or-later
  35. *
  36. */
  37. #include "qemu/osdep.h"
  38. #include "qemu/main-loop.h"
  39. #include "qemu/plugin.h"
  40. #include "qemu/log.h"
  41. #include "qemu/timer.h"
  42. #include "tcg/tcg.h"
  43. #include "exec/exec-all.h"
  44. #include "exec/gdbstub.h"
  45. #include "exec/translation-block.h"
  46. #include "exec/translator.h"
  47. #include "disas/disas.h"
  48. #include "plugin.h"
  49. #ifndef CONFIG_USER_ONLY
  50. #include "qapi/error.h"
  51. #include "migration/blocker.h"
  52. #include "exec/ram_addr.h"
  53. #include "qemu/plugin-memory.h"
  54. #include "hw/boards.h"
  55. #else
  56. #include "qemu.h"
  57. #ifdef CONFIG_LINUX
  58. #include "loader.h"
  59. #endif
  60. #endif
  61. /* Uninstall and Reset handlers */
  62. void qemu_plugin_uninstall(qemu_plugin_id_t id, qemu_plugin_simple_cb_t cb)
  63. {
  64. plugin_reset_uninstall(id, cb, false);
  65. }
  66. void qemu_plugin_reset(qemu_plugin_id_t id, qemu_plugin_simple_cb_t cb)
  67. {
  68. plugin_reset_uninstall(id, cb, true);
  69. }
  70. /*
  71. * Plugin Register Functions
  72. *
  73. * This allows the plugin to register callbacks for various events
  74. * during the translation.
  75. */
  76. void qemu_plugin_register_vcpu_init_cb(qemu_plugin_id_t id,
  77. qemu_plugin_vcpu_simple_cb_t cb)
  78. {
  79. plugin_register_cb(id, QEMU_PLUGIN_EV_VCPU_INIT, cb);
  80. }
  81. void qemu_plugin_register_vcpu_exit_cb(qemu_plugin_id_t id,
  82. qemu_plugin_vcpu_simple_cb_t cb)
  83. {
  84. plugin_register_cb(id, QEMU_PLUGIN_EV_VCPU_EXIT, cb);
  85. }
  86. static bool tb_is_mem_only(void)
  87. {
  88. return tb_cflags(tcg_ctx->gen_tb) & CF_MEMI_ONLY;
  89. }
  90. void qemu_plugin_register_vcpu_tb_exec_cb(struct qemu_plugin_tb *tb,
  91. qemu_plugin_vcpu_udata_cb_t cb,
  92. enum qemu_plugin_cb_flags flags,
  93. void *udata)
  94. {
  95. if (!tb_is_mem_only()) {
  96. plugin_register_dyn_cb__udata(&tb->cbs, cb, flags, udata);
  97. }
  98. }
  99. void qemu_plugin_register_vcpu_tb_exec_cond_cb(struct qemu_plugin_tb *tb,
  100. qemu_plugin_vcpu_udata_cb_t cb,
  101. enum qemu_plugin_cb_flags flags,
  102. enum qemu_plugin_cond cond,
  103. qemu_plugin_u64 entry,
  104. uint64_t imm,
  105. void *udata)
  106. {
  107. if (cond == QEMU_PLUGIN_COND_NEVER || tb_is_mem_only()) {
  108. return;
  109. }
  110. if (cond == QEMU_PLUGIN_COND_ALWAYS) {
  111. qemu_plugin_register_vcpu_tb_exec_cb(tb, cb, flags, udata);
  112. return;
  113. }
  114. plugin_register_dyn_cond_cb__udata(&tb->cbs, cb, flags,
  115. cond, entry, imm, udata);
  116. }
  117. void qemu_plugin_register_vcpu_tb_exec_inline_per_vcpu(
  118. struct qemu_plugin_tb *tb,
  119. enum qemu_plugin_op op,
  120. qemu_plugin_u64 entry,
  121. uint64_t imm)
  122. {
  123. if (!tb_is_mem_only()) {
  124. plugin_register_inline_op_on_entry(&tb->cbs, 0, op, entry, imm);
  125. }
  126. }
  127. void qemu_plugin_register_vcpu_insn_exec_cb(struct qemu_plugin_insn *insn,
  128. qemu_plugin_vcpu_udata_cb_t cb,
  129. enum qemu_plugin_cb_flags flags,
  130. void *udata)
  131. {
  132. if (!tb_is_mem_only()) {
  133. plugin_register_dyn_cb__udata(&insn->insn_cbs, cb, flags, udata);
  134. }
  135. }
  136. void qemu_plugin_register_vcpu_insn_exec_cond_cb(
  137. struct qemu_plugin_insn *insn,
  138. qemu_plugin_vcpu_udata_cb_t cb,
  139. enum qemu_plugin_cb_flags flags,
  140. enum qemu_plugin_cond cond,
  141. qemu_plugin_u64 entry,
  142. uint64_t imm,
  143. void *udata)
  144. {
  145. if (cond == QEMU_PLUGIN_COND_NEVER || tb_is_mem_only()) {
  146. return;
  147. }
  148. if (cond == QEMU_PLUGIN_COND_ALWAYS) {
  149. qemu_plugin_register_vcpu_insn_exec_cb(insn, cb, flags, udata);
  150. return;
  151. }
  152. plugin_register_dyn_cond_cb__udata(&insn->insn_cbs, cb, flags,
  153. cond, entry, imm, udata);
  154. }
  155. void qemu_plugin_register_vcpu_insn_exec_inline_per_vcpu(
  156. struct qemu_plugin_insn *insn,
  157. enum qemu_plugin_op op,
  158. qemu_plugin_u64 entry,
  159. uint64_t imm)
  160. {
  161. if (!tb_is_mem_only()) {
  162. plugin_register_inline_op_on_entry(&insn->insn_cbs, 0, op, entry, imm);
  163. }
  164. }
  165. /*
  166. * We always plant memory instrumentation because they don't finalise until
  167. * after the operation has complete.
  168. */
  169. void qemu_plugin_register_vcpu_mem_cb(struct qemu_plugin_insn *insn,
  170. qemu_plugin_vcpu_mem_cb_t cb,
  171. enum qemu_plugin_cb_flags flags,
  172. enum qemu_plugin_mem_rw rw,
  173. void *udata)
  174. {
  175. plugin_register_vcpu_mem_cb(&insn->mem_cbs, cb, flags, rw, udata);
  176. }
  177. void qemu_plugin_register_vcpu_mem_inline_per_vcpu(
  178. struct qemu_plugin_insn *insn,
  179. enum qemu_plugin_mem_rw rw,
  180. enum qemu_plugin_op op,
  181. qemu_plugin_u64 entry,
  182. uint64_t imm)
  183. {
  184. plugin_register_inline_op_on_entry(&insn->mem_cbs, rw, op, entry, imm);
  185. }
  186. void qemu_plugin_register_vcpu_tb_trans_cb(qemu_plugin_id_t id,
  187. qemu_plugin_vcpu_tb_trans_cb_t cb)
  188. {
  189. plugin_register_cb(id, QEMU_PLUGIN_EV_VCPU_TB_TRANS, cb);
  190. }
  191. void qemu_plugin_register_vcpu_syscall_cb(qemu_plugin_id_t id,
  192. qemu_plugin_vcpu_syscall_cb_t cb)
  193. {
  194. plugin_register_cb(id, QEMU_PLUGIN_EV_VCPU_SYSCALL, cb);
  195. }
  196. void
  197. qemu_plugin_register_vcpu_syscall_ret_cb(qemu_plugin_id_t id,
  198. qemu_plugin_vcpu_syscall_ret_cb_t cb)
  199. {
  200. plugin_register_cb(id, QEMU_PLUGIN_EV_VCPU_SYSCALL_RET, cb);
  201. }
  202. /*
  203. * Plugin Queries
  204. *
  205. * These are queries that the plugin can make to gauge information
  206. * from our opaque data types. We do not want to leak internal details
  207. * here just information useful to the plugin.
  208. */
  209. /*
  210. * Translation block information:
  211. *
  212. * A plugin can query the virtual address of the start of the block
  213. * and the number of instructions in it. It can also get access to
  214. * each translated instruction.
  215. */
  216. size_t qemu_plugin_tb_n_insns(const struct qemu_plugin_tb *tb)
  217. {
  218. return tb->n;
  219. }
  220. uint64_t qemu_plugin_tb_vaddr(const struct qemu_plugin_tb *tb)
  221. {
  222. const DisasContextBase *db = tcg_ctx->plugin_db;
  223. return db->pc_first;
  224. }
  225. struct qemu_plugin_insn *
  226. qemu_plugin_tb_get_insn(const struct qemu_plugin_tb *tb, size_t idx)
  227. {
  228. struct qemu_plugin_insn *insn;
  229. if (unlikely(idx >= tb->n)) {
  230. return NULL;
  231. }
  232. insn = g_ptr_array_index(tb->insns, idx);
  233. return insn;
  234. }
  235. /*
  236. * Instruction information
  237. *
  238. * These queries allow the plugin to retrieve information about each
  239. * instruction being translated.
  240. */
  241. size_t qemu_plugin_insn_data(const struct qemu_plugin_insn *insn,
  242. void *dest, size_t len)
  243. {
  244. const DisasContextBase *db = tcg_ctx->plugin_db;
  245. len = MIN(len, insn->len);
  246. return translator_st(db, dest, insn->vaddr, len) ? len : 0;
  247. }
  248. size_t qemu_plugin_insn_size(const struct qemu_plugin_insn *insn)
  249. {
  250. return insn->len;
  251. }
  252. uint64_t qemu_plugin_insn_vaddr(const struct qemu_plugin_insn *insn)
  253. {
  254. return insn->vaddr;
  255. }
  256. void *qemu_plugin_insn_haddr(const struct qemu_plugin_insn *insn)
  257. {
  258. const DisasContextBase *db = tcg_ctx->plugin_db;
  259. vaddr page0_last = db->pc_first | ~TARGET_PAGE_MASK;
  260. if (db->fake_insn) {
  261. return NULL;
  262. }
  263. /*
  264. * ??? The return value is not intended for use of host memory,
  265. * but as a proxy for address space and physical address.
  266. * Thus we are only interested in the first byte and do not
  267. * care about spanning pages.
  268. */
  269. if (insn->vaddr <= page0_last) {
  270. if (db->host_addr[0] == NULL) {
  271. return NULL;
  272. }
  273. return db->host_addr[0] + insn->vaddr - db->pc_first;
  274. } else {
  275. if (db->host_addr[1] == NULL) {
  276. return NULL;
  277. }
  278. return db->host_addr[1] + insn->vaddr - (page0_last + 1);
  279. }
  280. }
  281. char *qemu_plugin_insn_disas(const struct qemu_plugin_insn *insn)
  282. {
  283. return plugin_disas(tcg_ctx->cpu, tcg_ctx->plugin_db,
  284. insn->vaddr, insn->len);
  285. }
  286. const char *qemu_plugin_insn_symbol(const struct qemu_plugin_insn *insn)
  287. {
  288. const char *sym = lookup_symbol(insn->vaddr);
  289. return sym[0] != 0 ? sym : NULL;
  290. }
  291. /*
  292. * The memory queries allow the plugin to query information about a
  293. * memory access.
  294. */
  295. unsigned qemu_plugin_mem_size_shift(qemu_plugin_meminfo_t info)
  296. {
  297. MemOp op = get_memop(info);
  298. return op & MO_SIZE;
  299. }
  300. bool qemu_plugin_mem_is_sign_extended(qemu_plugin_meminfo_t info)
  301. {
  302. MemOp op = get_memop(info);
  303. return op & MO_SIGN;
  304. }
  305. bool qemu_plugin_mem_is_big_endian(qemu_plugin_meminfo_t info)
  306. {
  307. MemOp op = get_memop(info);
  308. return (op & MO_BSWAP) == MO_BE;
  309. }
  310. bool qemu_plugin_mem_is_store(qemu_plugin_meminfo_t info)
  311. {
  312. return get_plugin_meminfo_rw(info) & QEMU_PLUGIN_MEM_W;
  313. }
  314. qemu_plugin_mem_value qemu_plugin_mem_get_value(qemu_plugin_meminfo_t info)
  315. {
  316. uint64_t low = current_cpu->neg.plugin_mem_value_low;
  317. qemu_plugin_mem_value value;
  318. switch (qemu_plugin_mem_size_shift(info)) {
  319. case 0:
  320. value.type = QEMU_PLUGIN_MEM_VALUE_U8;
  321. value.data.u8 = (uint8_t)low;
  322. break;
  323. case 1:
  324. value.type = QEMU_PLUGIN_MEM_VALUE_U16;
  325. value.data.u16 = (uint16_t)low;
  326. break;
  327. case 2:
  328. value.type = QEMU_PLUGIN_MEM_VALUE_U32;
  329. value.data.u32 = (uint32_t)low;
  330. break;
  331. case 3:
  332. value.type = QEMU_PLUGIN_MEM_VALUE_U64;
  333. value.data.u64 = low;
  334. break;
  335. case 4:
  336. value.type = QEMU_PLUGIN_MEM_VALUE_U128;
  337. value.data.u128.low = low;
  338. value.data.u128.high = current_cpu->neg.plugin_mem_value_high;
  339. break;
  340. default:
  341. g_assert_not_reached();
  342. }
  343. return value;
  344. }
  345. /*
  346. * Virtual Memory queries
  347. */
  348. #ifdef CONFIG_SOFTMMU
  349. static __thread struct qemu_plugin_hwaddr hwaddr_info;
  350. #endif
  351. struct qemu_plugin_hwaddr *qemu_plugin_get_hwaddr(qemu_plugin_meminfo_t info,
  352. uint64_t vaddr)
  353. {
  354. #ifdef CONFIG_SOFTMMU
  355. CPUState *cpu = current_cpu;
  356. unsigned int mmu_idx = get_mmuidx(info);
  357. enum qemu_plugin_mem_rw rw = get_plugin_meminfo_rw(info);
  358. hwaddr_info.is_store = (rw & QEMU_PLUGIN_MEM_W) != 0;
  359. assert(mmu_idx < NB_MMU_MODES);
  360. if (!tlb_plugin_lookup(cpu, vaddr, mmu_idx,
  361. hwaddr_info.is_store, &hwaddr_info)) {
  362. error_report("invalid use of qemu_plugin_get_hwaddr");
  363. return NULL;
  364. }
  365. return &hwaddr_info;
  366. #else
  367. return NULL;
  368. #endif
  369. }
  370. bool qemu_plugin_hwaddr_is_io(const struct qemu_plugin_hwaddr *haddr)
  371. {
  372. #ifdef CONFIG_SOFTMMU
  373. return haddr->is_io;
  374. #else
  375. return false;
  376. #endif
  377. }
  378. uint64_t qemu_plugin_hwaddr_phys_addr(const struct qemu_plugin_hwaddr *haddr)
  379. {
  380. #ifdef CONFIG_SOFTMMU
  381. if (haddr) {
  382. return haddr->phys_addr;
  383. }
  384. #endif
  385. return 0;
  386. }
  387. const char *qemu_plugin_hwaddr_device_name(const struct qemu_plugin_hwaddr *h)
  388. {
  389. #ifdef CONFIG_SOFTMMU
  390. if (h && h->is_io) {
  391. MemoryRegion *mr = h->mr;
  392. if (!mr->name) {
  393. unsigned maddr = (uintptr_t)mr;
  394. g_autofree char *temp = g_strdup_printf("anon%08x", maddr);
  395. return g_intern_string(temp);
  396. } else {
  397. return g_intern_string(mr->name);
  398. }
  399. } else {
  400. return g_intern_static_string("RAM");
  401. }
  402. #else
  403. return g_intern_static_string("Invalid");
  404. #endif
  405. }
  406. int qemu_plugin_num_vcpus(void)
  407. {
  408. return plugin_num_vcpus();
  409. }
  410. /*
  411. * Plugin output
  412. */
  413. void qemu_plugin_outs(const char *string)
  414. {
  415. qemu_log_mask(CPU_LOG_PLUGIN, "%s", string);
  416. }
  417. bool qemu_plugin_bool_parse(const char *name, const char *value, bool *ret)
  418. {
  419. return name && value && qapi_bool_parse(name, value, ret, NULL);
  420. }
  421. /*
  422. * Binary path, start and end locations
  423. */
  424. const char *qemu_plugin_path_to_binary(void)
  425. {
  426. char *path = NULL;
  427. #ifdef CONFIG_USER_ONLY
  428. TaskState *ts = get_task_state(current_cpu);
  429. path = g_strdup(ts->bprm->filename);
  430. #endif
  431. return path;
  432. }
  433. uint64_t qemu_plugin_start_code(void)
  434. {
  435. uint64_t start = 0;
  436. #ifdef CONFIG_USER_ONLY
  437. TaskState *ts = get_task_state(current_cpu);
  438. start = ts->info->start_code;
  439. #endif
  440. return start;
  441. }
  442. uint64_t qemu_plugin_end_code(void)
  443. {
  444. uint64_t end = 0;
  445. #ifdef CONFIG_USER_ONLY
  446. TaskState *ts = get_task_state(current_cpu);
  447. end = ts->info->end_code;
  448. #endif
  449. return end;
  450. }
  451. uint64_t qemu_plugin_entry_code(void)
  452. {
  453. uint64_t entry = 0;
  454. #ifdef CONFIG_USER_ONLY
  455. TaskState *ts = get_task_state(current_cpu);
  456. entry = ts->info->entry;
  457. #endif
  458. return entry;
  459. }
  460. /*
  461. * Create register handles.
  462. *
  463. * We need to create a handle for each register so the plugin
  464. * infrastructure can call gdbstub to read a register. They are
  465. * currently just a pointer encapsulation of the gdb_reg but in
  466. * future may hold internal plugin state so its important plugin
  467. * authors are not tempted to treat them as numbers.
  468. *
  469. * We also construct a result array with those handles and some
  470. * ancillary data the plugin might find useful.
  471. */
  472. static GArray *create_register_handles(GArray *gdbstub_regs)
  473. {
  474. GArray *find_data = g_array_new(true, true,
  475. sizeof(qemu_plugin_reg_descriptor));
  476. for (int i = 0; i < gdbstub_regs->len; i++) {
  477. GDBRegDesc *grd = &g_array_index(gdbstub_regs, GDBRegDesc, i);
  478. qemu_plugin_reg_descriptor desc;
  479. /* skip "un-named" regs */
  480. if (!grd->name) {
  481. continue;
  482. }
  483. /* Create a record for the plugin */
  484. desc.handle = GINT_TO_POINTER(grd->gdb_reg + 1);
  485. desc.name = g_intern_string(grd->name);
  486. desc.feature = g_intern_string(grd->feature_name);
  487. g_array_append_val(find_data, desc);
  488. }
  489. return find_data;
  490. }
  491. GArray *qemu_plugin_get_registers(void)
  492. {
  493. g_assert(current_cpu);
  494. g_autoptr(GArray) regs = gdb_get_register_list(current_cpu);
  495. return create_register_handles(regs);
  496. }
  497. bool qemu_plugin_read_memory_vaddr(uint64_t addr, GByteArray *data, size_t len)
  498. {
  499. g_assert(current_cpu);
  500. if (len == 0) {
  501. return false;
  502. }
  503. g_byte_array_set_size(data, len);
  504. int result = cpu_memory_rw_debug(current_cpu, addr, data->data,
  505. data->len, false);
  506. if (result < 0) {
  507. return false;
  508. }
  509. return true;
  510. }
  511. int qemu_plugin_read_register(struct qemu_plugin_register *reg, GByteArray *buf)
  512. {
  513. g_assert(current_cpu);
  514. return gdb_read_register(current_cpu, buf, GPOINTER_TO_INT(reg) - 1);
  515. }
  516. struct qemu_plugin_scoreboard *qemu_plugin_scoreboard_new(size_t element_size)
  517. {
  518. return plugin_scoreboard_new(element_size);
  519. }
  520. void qemu_plugin_scoreboard_free(struct qemu_plugin_scoreboard *score)
  521. {
  522. plugin_scoreboard_free(score);
  523. }
  524. void *qemu_plugin_scoreboard_find(struct qemu_plugin_scoreboard *score,
  525. unsigned int vcpu_index)
  526. {
  527. g_assert(vcpu_index < qemu_plugin_num_vcpus());
  528. /* we can't use g_array_index since entry size is not statically known */
  529. char *base_ptr = score->data->data;
  530. return base_ptr + vcpu_index * g_array_get_element_size(score->data);
  531. }
  532. static uint64_t *plugin_u64_address(qemu_plugin_u64 entry,
  533. unsigned int vcpu_index)
  534. {
  535. char *ptr = qemu_plugin_scoreboard_find(entry.score, vcpu_index);
  536. return (uint64_t *)(ptr + entry.offset);
  537. }
  538. void qemu_plugin_u64_add(qemu_plugin_u64 entry, unsigned int vcpu_index,
  539. uint64_t added)
  540. {
  541. *plugin_u64_address(entry, vcpu_index) += added;
  542. }
  543. uint64_t qemu_plugin_u64_get(qemu_plugin_u64 entry,
  544. unsigned int vcpu_index)
  545. {
  546. return *plugin_u64_address(entry, vcpu_index);
  547. }
  548. void qemu_plugin_u64_set(qemu_plugin_u64 entry, unsigned int vcpu_index,
  549. uint64_t val)
  550. {
  551. *plugin_u64_address(entry, vcpu_index) = val;
  552. }
  553. uint64_t qemu_plugin_u64_sum(qemu_plugin_u64 entry)
  554. {
  555. uint64_t total = 0;
  556. for (int i = 0, n = qemu_plugin_num_vcpus(); i < n; ++i) {
  557. total += qemu_plugin_u64_get(entry, i);
  558. }
  559. return total;
  560. }
  561. /*
  562. * Time control
  563. */
  564. static bool has_control;
  565. #ifdef CONFIG_SOFTMMU
  566. static Error *migration_blocker;
  567. #endif
  568. const void *qemu_plugin_request_time_control(void)
  569. {
  570. if (!has_control) {
  571. has_control = true;
  572. #ifdef CONFIG_SOFTMMU
  573. error_setg(&migration_blocker,
  574. "TCG plugin time control does not support migration");
  575. migrate_add_blocker(&migration_blocker, NULL);
  576. #endif
  577. return &has_control;
  578. }
  579. return NULL;
  580. }
  581. #ifdef CONFIG_SOFTMMU
  582. static void advance_virtual_time__async(CPUState *cpu, run_on_cpu_data data)
  583. {
  584. int64_t new_time = data.host_ulong;
  585. qemu_clock_advance_virtual_time(new_time);
  586. }
  587. #endif
  588. void qemu_plugin_update_ns(const void *handle, int64_t new_time)
  589. {
  590. #ifdef CONFIG_SOFTMMU
  591. if (handle == &has_control) {
  592. /* Need to execute out of cpu_exec, so bql can be locked. */
  593. async_run_on_cpu(current_cpu,
  594. advance_virtual_time__async,
  595. RUN_ON_CPU_HOST_ULONG(new_time));
  596. }
  597. #endif
  598. }