Lines Matching refs:balloon

187 static uint64_t hv_balloon_total_our_ram(HvBalloon *balloon)  in hv_balloon_total_our_ram()  argument
189 if (!balloon->our_range) { in hv_balloon_total_our_ram()
193 return balloon->our_range->range.added; in hv_balloon_total_our_ram()
230 static uint64_t hv_balloon_total_ram(HvBalloon *balloon) in hv_balloon_total_ram() argument
234 uint64_t our_ram_size_pages = hv_balloon_total_our_ram(balloon); in hv_balloon_total_ram()
245 static uint64_t hv_balloon_total_removed_rs(HvBalloon *balloon, in hv_balloon_total_removed_rs() argument
250 total_removed = SUM_SATURATE_U64(balloon->removed_guest_ctr, in hv_balloon_total_removed_rs()
251 balloon->removed_both_ctr); in hv_balloon_total_removed_rs()
262 static bool hv_balloon_state_set(HvBalloon *balloon, in hv_balloon_state_set() argument
265 if (newst == S_NO_CHANGE || balloon->state == newst) { in hv_balloon_state_set()
269 balloon->state = newst; in hv_balloon_state_set()
286 static VMBusChannel *hv_balloon_get_channel_maybe(HvBalloon *balloon) in hv_balloon_get_channel_maybe() argument
288 return vmbus_device_channel(&balloon->parent, 0); in hv_balloon_get_channel_maybe()
291 static VMBusChannel *hv_balloon_get_channel(HvBalloon *balloon) in hv_balloon_get_channel() argument
295 chan = hv_balloon_get_channel_maybe(balloon); in hv_balloon_get_channel()
315 static bool hv_balloon_unballoon_get_source(HvBalloon *balloon, in hv_balloon_unballoon_get_source() argument
320 OurRange *our_range = OUR_RANGE(balloon->our_range); in hv_balloon_unballoon_get_source()
323 if (g_tree_nnodes(balloon->removed_guest.t) > 0) { in hv_balloon_unballoon_get_source()
324 *dtree = balloon->removed_guest; in hv_balloon_unballoon_get_source()
325 *dctr = &balloon->removed_guest_ctr; in hv_balloon_unballoon_get_source()
327 } else if (g_tree_nnodes(balloon->removed_both.t) > 0) { in hv_balloon_unballoon_get_source()
328 *dtree = balloon->removed_both; in hv_balloon_unballoon_get_source()
329 *dctr = &balloon->removed_both_ctr; in hv_balloon_unballoon_get_source()
335 *dctr = &balloon->removed_guest_ctr; in hv_balloon_unballoon_get_source()
339 *dctr = &balloon->removed_both_ctr; in hv_balloon_unballoon_get_source()
348 static void hv_balloon_unballoon_rb_wait(HvBalloon *balloon, StateDesc *stdesc) in hv_balloon_unballoon_rb_wait() argument
350 VMBusChannel *chan = hv_balloon_get_channel(balloon); in hv_balloon_unballoon_rb_wait()
354 assert(balloon->state == S_UNBALLOON_RB_WAIT); in hv_balloon_unballoon_rb_wait()
363 static void hv_balloon_unballoon_posting(HvBalloon *balloon, StateDesc *stdesc) in hv_balloon_unballoon_posting() argument
365 VMBusChannel *chan = hv_balloon_get_channel(balloon); in hv_balloon_unballoon_posting()
375 assert(balloon->state == S_UNBALLOON_POSTING); in hv_balloon_unballoon_posting()
376 assert(balloon->unballoon_diff > 0); in hv_balloon_unballoon_posting()
378 if (!hv_balloon_unballoon_get_source(balloon, &dtree, &dctr, &our_range)) { in hv_balloon_unballoon_posting()
387 assert(balloon->our_range || !our_range); in hv_balloon_unballoon_posting()
394 ur->hdr.trans_id = balloon->trans_id; in hv_balloon_unballoon_posting()
396 bret = hvb_page_range_tree_pop(dtree, &range, MIN(balloon->unballoon_diff, in hv_balloon_unballoon_posting()
402 balloon->unballoon_diff -= range.count; in hv_balloon_unballoon_posting()
407 ur->more_pages = balloon->unballoon_diff > 0; in hv_balloon_unballoon_posting()
411 balloon->unballoon_diff); in hv_balloon_unballoon_posting()
428 static bool hv_balloon_our_range_ensure(HvBalloon *balloon) in hv_balloon_our_range_ensure() argument
435 if (balloon->our_range) { in hv_balloon_our_range_ensure()
439 if (!balloon->hostmem) { in hv_balloon_our_range_ensure()
443 align = (1 << balloon->caps.cap_bits.hot_add_alignment) * MiB; in hv_balloon_our_range_ensure()
444 assert(QEMU_IS_ALIGNED(balloon->addr, align)); in hv_balloon_our_range_ensure()
446 hostmem_mr = host_memory_backend_get_memory(balloon->hostmem); in hv_balloon_our_range_ensure()
448 our_range_memslots = hvb_our_range_memslots_new(balloon->addr, in hv_balloon_our_range_ensure()
449 balloon->mr, hostmem_mr, in hv_balloon_our_range_ensure()
450 OBJECT(balloon), in hv_balloon_our_range_ensure()
451 balloon->memslot_count, in hv_balloon_our_range_ensure()
452 balloon->memslot_size); in hv_balloon_our_range_ensure()
455 if (hvb_page_range_tree_intree_any(balloon->removed_guest, in hv_balloon_our_range_ensure()
458 hvb_page_range_tree_intree_any(balloon->removed_both, in hv_balloon_our_range_ensure()
468 balloon->our_range = g_steal_pointer(&our_range_memslots); in hv_balloon_our_range_ensure()
472 static void hv_balloon_hot_add_setup(HvBalloon *balloon, StateDesc *stdesc) in hv_balloon_hot_add_setup() argument
475 uint64_t hot_add_diff = balloon->hot_add_diff; in hv_balloon_hot_add_setup()
476 PageRange *hot_add_range = &balloon->hot_add_range; in hv_balloon_hot_add_setup()
480 assert(balloon->state == S_HOT_ADD_SETUP); in hv_balloon_hot_add_setup()
483 if (!hv_balloon_our_range_ensure(balloon)) { in hv_balloon_hot_add_setup()
487 our_range = OUR_RANGE(balloon->our_range); in hv_balloon_hot_add_setup()
489 align = (1 << balloon->caps.cap_bits.hot_add_alignment) * in hv_balloon_hot_add_setup()
503 hvb_our_range_memslots_ensure_mapped_additional(balloon->our_range, in hv_balloon_hot_add_setup()
513 static void hv_balloon_hot_add_rb_wait(HvBalloon *balloon, StateDesc *stdesc) in hv_balloon_hot_add_rb_wait() argument
515 VMBusChannel *chan = hv_balloon_get_channel(balloon); in hv_balloon_hot_add_rb_wait()
519 assert(balloon->state == S_HOT_ADD_RB_WAIT); in hv_balloon_hot_add_rb_wait()
528 static void hv_balloon_hot_add_posting(HvBalloon *balloon, StateDesc *stdesc) in hv_balloon_hot_add_posting() argument
530 PageRange *hot_add_range = &balloon->hot_add_range; in hv_balloon_hot_add_posting()
531 uint64_t *current_count = &balloon->ha_current_count; in hv_balloon_hot_add_posting()
532 VMBusChannel *chan = hv_balloon_get_channel(balloon); in hv_balloon_hot_add_posting()
539 assert(balloon->state == S_HOT_ADD_POSTING); in hv_balloon_hot_add_posting()
542 align = (1 << balloon->caps.cap_bits.hot_add_alignment) * in hv_balloon_hot_add_posting()
566 ha->hdr.trans_id = balloon->trans_id; in hv_balloon_hot_add_posting()
587 static void hv_balloon_balloon_rb_wait(HvBalloon *balloon, StateDesc *stdesc) in hv_balloon_balloon_rb_wait() argument
589 VMBusChannel *chan = hv_balloon_get_channel(balloon); in hv_balloon_balloon_rb_wait()
592 assert(balloon->state == S_BALLOON_RB_WAIT); in hv_balloon_balloon_rb_wait()
601 static void hv_balloon_balloon_posting(HvBalloon *balloon, StateDesc *stdesc) in hv_balloon_balloon_posting() argument
603 VMBusChannel *chan = hv_balloon_get_channel(balloon); in hv_balloon_balloon_posting()
608 assert(balloon->state == S_BALLOON_POSTING); in hv_balloon_balloon_posting()
609 assert(balloon->balloon_diff > 0); in hv_balloon_balloon_posting()
614 bl.hdr.trans_id = balloon->trans_id; in hv_balloon_balloon_posting()
615 bl.num_pages = MIN(balloon->balloon_diff, HV_BALLOON_HR_CHUNK_PAGES); in hv_balloon_balloon_posting()
618 balloon->balloon_diff); in hv_balloon_balloon_posting()
631 static void hv_balloon_idle_state_process_target(HvBalloon *balloon, in hv_balloon_idle_state_process_target() argument
634 bool can_balloon = balloon->caps.cap_bits.balloon; in hv_balloon_idle_state_process_target()
637 ram_size_pages = hv_balloon_total_ram(balloon); in hv_balloon_idle_state_process_target()
638 total_removed = hv_balloon_total_removed_rs(balloon, ram_size_pages); in hv_balloon_idle_state_process_target()
645 if (balloon->target > ram_size_pages - total_removed) { in hv_balloon_idle_state_process_target()
646 bool can_hot_add = balloon->caps.cap_bits.hot_add; in hv_balloon_idle_state_process_target()
647 uint64_t target_diff = balloon->target - in hv_balloon_idle_state_process_target()
650 balloon->unballoon_diff = MIN(target_diff, total_removed); in hv_balloon_idle_state_process_target()
653 balloon->hot_add_diff = target_diff - balloon->unballoon_diff; in hv_balloon_idle_state_process_target()
655 balloon->hot_add_diff = 0; in hv_balloon_idle_state_process_target()
658 if (balloon->unballoon_diff > 0) { in hv_balloon_idle_state_process_target()
661 } else if (balloon->hot_add_diff > 0) { in hv_balloon_idle_state_process_target()
665 balloon->target < ram_size_pages - total_removed) { in hv_balloon_idle_state_process_target()
666 balloon->balloon_diff = ram_size_pages - total_removed - in hv_balloon_idle_state_process_target()
667 balloon->target; in hv_balloon_idle_state_process_target()
672 static void hv_balloon_idle_state(HvBalloon *balloon, in hv_balloon_idle_state() argument
675 assert(balloon->state == S_IDLE); in hv_balloon_idle_state()
677 if (balloon->target_changed) { in hv_balloon_idle_state()
678 balloon->target_changed = false; in hv_balloon_idle_state()
679 hv_balloon_idle_state_process_target(balloon, stdesc); in hv_balloon_idle_state()
685 void (*handler)(HvBalloon *balloon, StateDesc *stdesc);
697 static void hv_balloon_handle_state(HvBalloon *balloon, StateDesc *stdesc) in hv_balloon_handle_state() argument
699 if (balloon->state >= ARRAY_SIZE(state_handlers) || in hv_balloon_handle_state()
700 !state_handlers[balloon->state].handler) { in hv_balloon_handle_state()
704 state_handlers[balloon->state].handler(balloon, stdesc); in hv_balloon_handle_state()
732 static void hv_balloon_remove_response_handle_range(HvBalloon *balloon, in hv_balloon_remove_response_handle_range() argument
737 OurRange *our_range = OUR_RANGE(balloon->our_range); in hv_balloon_remove_response_handle_range()
739 both ? balloon->removed_both : balloon->removed_guest; in hv_balloon_remove_response_handle_range()
741 both ? &balloon->removed_both_ctr : &balloon->removed_guest_ctr; in hv_balloon_remove_response_handle_range()
804 static void hv_balloon_remove_response_handle_pages(HvBalloon *balloon, in hv_balloon_remove_response_handle_pages() argument
818 hv_balloon_remove_response_handle_range(balloon, range, both, in hv_balloon_remove_response_handle_pages()
904 static void hv_balloon_handle_remove_ranges(HvBalloon *balloon, in hv_balloon_handle_remove_ranges() argument
958 hv_balloon_remove_response_handle_pages(balloon, in hv_balloon_handle_remove_ranges()
963 hv_balloon_remove_response_handle_pages(balloon, in hv_balloon_handle_remove_ranges()
977 hv_balloon_remove_response_handle_range(balloon, &range_both, true, in hv_balloon_handle_remove_ranges()
979 hv_balloon_remove_response_handle_range(balloon, &range_guest, false, in hv_balloon_handle_remove_ranges()
985 if (removedcnt > balloon->balloon_diff) { in hv_balloon_handle_remove_ranges()
987 removedcnt, balloon->balloon_diff); in hv_balloon_handle_remove_ranges()
988 balloon->balloon_diff = 0; in hv_balloon_handle_remove_ranges()
990 balloon->balloon_diff -= removedcnt; in hv_balloon_handle_remove_ranges()
1009 static void hv_balloon_handle_version_request(HvBalloon *balloon, in hv_balloon_handle_version_request() argument
1017 if (balloon->state != S_VERSION) { in hv_balloon_handle_version_request()
1019 balloon->state); in hv_balloon_handle_version_request()
1045 static void hv_balloon_handle_caps_report(HvBalloon *balloon, in hv_balloon_handle_caps_report() argument
1053 if (balloon->state != S_CAPS) { in hv_balloon_handle_caps_report()
1055 balloon->state); in hv_balloon_handle_caps_report()
1065 balloon->caps = msgCap->caps; in hv_balloon_handle_caps_report()
1073 respCap.suppress_pressure_reports = !balloon->status_report.enabled; in hv_balloon_handle_caps_report()
1076 timer_mod(&balloon->post_init_timer, in hv_balloon_handle_caps_report()
1083 static void hv_balloon_handle_status_report(HvBalloon *balloon, in hv_balloon_handle_status_report() argument
1094 if (!balloon->status_report.enabled) { in hv_balloon_handle_status_report()
1098 balloon->status_report.committed = msgStatus->num_committed; in hv_balloon_handle_status_report()
1099 balloon->status_report.committed *= HV_BALLOON_PAGE_SIZE; in hv_balloon_handle_status_report()
1100 balloon->status_report.available = msgStatus->num_avail; in hv_balloon_handle_status_report()
1101 balloon->status_report.available *= HV_BALLOON_PAGE_SIZE; in hv_balloon_handle_status_report()
1102 balloon->status_report.received = true; in hv_balloon_handle_status_report()
1104 qapi_event_send_hv_balloon_status_report(balloon->status_report.committed, in hv_balloon_handle_status_report()
1105 balloon->status_report.available); in hv_balloon_handle_status_report()
1110 HvBalloon *balloon; in qmp_query_hv_balloon_status_report() local
1113 balloon = HV_BALLOON(object_resolve_path_type("", TYPE_HV_BALLOON, NULL)); in qmp_query_hv_balloon_status_report()
1114 if (!balloon) { in qmp_query_hv_balloon_status_report()
1119 if (!balloon->status_report.enabled) { in qmp_query_hv_balloon_status_report()
1124 if (!balloon->status_report.received) { in qmp_query_hv_balloon_status_report()
1130 info->committed = balloon->status_report.committed; in qmp_query_hv_balloon_status_report()
1131 info->available = balloon->status_report.available; in qmp_query_hv_balloon_status_report()
1135 static void hv_balloon_handle_unballoon_response(HvBalloon *balloon, in hv_balloon_handle_unballoon_response() argument
1142 if (balloon->state != S_UNBALLOON_REPLY_WAIT) { in hv_balloon_handle_unballoon_response()
1144 balloon->state); in hv_balloon_handle_unballoon_response()
1154 balloon->trans_id++; in hv_balloon_handle_unballoon_response()
1156 if (balloon->hot_add_diff > 0) { in hv_balloon_handle_unballoon_response()
1157 bool can_hot_add = balloon->caps.cap_bits.hot_add; in hv_balloon_handle_unballoon_response()
1166 static void hv_balloon_handle_hot_add_response(HvBalloon *balloon, in hv_balloon_handle_hot_add_response() argument
1170 PageRange *hot_add_range = &balloon->hot_add_range; in hv_balloon_handle_hot_add_response()
1175 if (balloon->state != S_HOT_ADD_REPLY_WAIT) { in hv_balloon_handle_hot_add_response()
1177 balloon->state); in hv_balloon_handle_hot_add_response()
1181 assert(balloon->our_range); in hv_balloon_handle_hot_add_response()
1182 our_range = OUR_RANGE(balloon->our_range); in hv_balloon_handle_hot_add_response()
1191 balloon->trans_id++; in hv_balloon_handle_hot_add_response()
1194 if (msgHaR->page_count > balloon->ha_current_count) { in hv_balloon_handle_hot_add_response()
1196 msgHaR->page_count, balloon->ha_current_count); in hv_balloon_handle_hot_add_response()
1197 msgHaR->page_count = balloon->ha_current_count; in hv_balloon_handle_hot_add_response()
1205 if (!msgHaR->result || msgHaR->page_count < balloon->ha_current_count) { in hv_balloon_handle_hot_add_response()
1225 static void hv_balloon_handle_balloon_response(HvBalloon *balloon, in hv_balloon_handle_balloon_response() argument
1232 if (balloon->state != S_BALLOON_REPLY_WAIT) { in hv_balloon_handle_balloon_response()
1234 balloon->state); in hv_balloon_handle_balloon_response()
1253 balloon->balloon_diff = 0; in hv_balloon_handle_balloon_response()
1256 hv_balloon_handle_remove_ranges(balloon, in hv_balloon_handle_balloon_response()
1267 balloon->trans_id++; in hv_balloon_handle_balloon_response()
1269 if (balloon->balloon_diff > 0) { in hv_balloon_handle_balloon_response()
1276 static void hv_balloon_handle_packet(HvBalloon *balloon, HvBalloonReq *req, in hv_balloon_handle_packet() argument
1288 hv_balloon_handle_version_request(balloon, req, stdesc); in hv_balloon_handle_packet()
1292 hv_balloon_handle_caps_report(balloon, req, stdesc); in hv_balloon_handle_packet()
1296 hv_balloon_handle_status_report(balloon, req); in hv_balloon_handle_packet()
1300 hv_balloon_handle_hot_add_response(balloon, req, stdesc); in hv_balloon_handle_packet()
1304 hv_balloon_handle_unballoon_response(balloon, req, stdesc); in hv_balloon_handle_packet()
1308 hv_balloon_handle_balloon_response(balloon, req, stdesc); in hv_balloon_handle_packet()
1317 static bool hv_balloon_recv_channel(HvBalloon *balloon, StateDesc *stdesc) in hv_balloon_recv_channel() argument
1322 if (balloon->state == S_WAIT_RESET || in hv_balloon_recv_channel()
1323 balloon->state == S_POST_RESET_CLOSED) { in hv_balloon_recv_channel()
1327 chan = hv_balloon_get_channel(balloon); in hv_balloon_recv_channel()
1333 hv_balloon_handle_packet(balloon, req, stdesc); in hv_balloon_recv_channel()
1346 static bool hv_balloon_event_loop_state(HvBalloon *balloon) in hv_balloon_event_loop_state() argument
1350 hv_balloon_handle_state(balloon, &state_new); in hv_balloon_event_loop_state()
1351 return hv_balloon_state_set(balloon, state_new.state, state_new.desc); in hv_balloon_event_loop_state()
1355 static bool hv_balloon_event_loop_recv(HvBalloon *balloon) in hv_balloon_event_loop_recv() argument
1360 any_recv = hv_balloon_recv_channel(balloon, &state_new); in hv_balloon_event_loop_recv()
1361 state_changed = hv_balloon_state_set(balloon, in hv_balloon_event_loop_recv()
1367 static void hv_balloon_event_loop(HvBalloon *balloon) in hv_balloon_event_loop() argument
1372 state_repeat = hv_balloon_event_loop_state(balloon); in hv_balloon_event_loop()
1373 recv_repeat = hv_balloon_event_loop_recv(balloon); in hv_balloon_event_loop()
1379 HvBalloon *balloon = HV_BALLOON(vmbus_channel_device(chan)); in hv_balloon_vmdev_chan_notify() local
1381 hv_balloon_event_loop(balloon); in hv_balloon_vmdev_chan_notify()
1386 HvBalloon *balloon = opaque; in hv_balloon_stat() local
1387 info->actual = (hv_balloon_total_ram(balloon) - balloon->removed_both_ctr) in hv_balloon_stat()
1393 HvBalloon *balloon = opaque; in hv_balloon_to_target() local
1404 balloon->target = target_pages; in hv_balloon_to_target()
1405 balloon->target_changed = true; in hv_balloon_to_target()
1407 hv_balloon_event_loop(balloon); in hv_balloon_to_target()
1412 HvBalloon *balloon = HV_BALLOON(vmbus_channel_device(chan)); in hv_balloon_vmdev_open_channel() local
1414 if (balloon->state != S_POST_RESET_CLOSED) { in hv_balloon_vmdev_open_channel()
1416 balloon->state); in hv_balloon_vmdev_open_channel()
1420 HV_BALLOON_SET_STATE(balloon, S_VERSION); in hv_balloon_vmdev_open_channel()
1421 hv_balloon_event_loop(balloon); in hv_balloon_vmdev_open_channel()
1428 HvBalloon *balloon = HV_BALLOON(vmbus_channel_device(chan)); in hv_balloon_vmdev_close_channel() local
1430 timer_del(&balloon->post_init_timer); in hv_balloon_vmdev_close_channel()
1433 balloon->status_report.received = false; in hv_balloon_vmdev_close_channel()
1435 HV_BALLOON_SET_STATE(balloon, S_WAIT_RESET); in hv_balloon_vmdev_close_channel()
1436 hv_balloon_event_loop(balloon); in hv_balloon_vmdev_close_channel()
1441 HvBalloon *balloon = opaque; in hv_balloon_post_init_timer() local
1443 if (balloon->state != S_POST_INIT_WAIT) { in hv_balloon_post_init_timer()
1447 HV_BALLOON_SET_STATE(balloon, S_IDLE); in hv_balloon_post_init_timer()
1448 hv_balloon_event_loop(balloon); in hv_balloon_post_init_timer()
1451 static void hv_balloon_system_reset_unrealize_common(HvBalloon *balloon) in hv_balloon_system_reset_unrealize_common() argument
1453 g_clear_pointer(&balloon->our_range, hvb_our_range_memslots_free); in hv_balloon_system_reset_unrealize_common()
1458 HvBalloon *balloon = HV_BALLOON(opaque); in hv_balloon_system_reset() local
1460 hv_balloon_system_reset_unrealize_common(balloon); in hv_balloon_system_reset()
1463 static void hv_balloon_ensure_mr(HvBalloon *balloon) in hv_balloon_ensure_mr() argument
1467 assert(balloon->hostmem); in hv_balloon_ensure_mr()
1469 if (balloon->mr) { in hv_balloon_ensure_mr()
1473 hostmem_mr = host_memory_backend_get_memory(balloon->hostmem); in hv_balloon_ensure_mr()
1475 balloon->mr = g_new0(MemoryRegion, 1); in hv_balloon_ensure_mr()
1476 memory_region_init(balloon->mr, OBJECT(balloon), TYPE_HV_BALLOON, in hv_balloon_ensure_mr()
1478 balloon->mr->align = memory_region_get_alignment(hostmem_mr); in hv_balloon_ensure_mr()
1481 static void hv_balloon_free_mr(HvBalloon *balloon) in hv_balloon_free_mr() argument
1483 if (!balloon->mr) { in hv_balloon_free_mr()
1487 object_unparent(OBJECT(balloon->mr)); in hv_balloon_free_mr()
1488 g_clear_pointer(&balloon->mr, g_free); in hv_balloon_free_mr()
1494 HvBalloon *balloon = HV_BALLOON(vdev); in hv_balloon_vmdev_realize() local
1497 balloon->state = S_WAIT_RESET; in hv_balloon_vmdev_realize()
1500 balloon); in hv_balloon_vmdev_realize()
1507 if (balloon->hostmem) { in hv_balloon_vmdev_realize()
1508 if (host_memory_backend_is_mapped(balloon->hostmem)) { in hv_balloon_vmdev_realize()
1509 Object *obj = OBJECT(balloon->hostmem); in hv_balloon_vmdev_realize()
1517 hv_balloon_ensure_mr(balloon); in hv_balloon_vmdev_realize()
1520 if (!QEMU_IS_ALIGNED(memory_region_size(balloon->mr), in hv_balloon_vmdev_realize()
1527 host_memory_backend_set_mapped(balloon->hostmem, true); in hv_balloon_vmdev_realize()
1528 vmstate_register_ram(host_memory_backend_get_memory(balloon->hostmem), in hv_balloon_vmdev_realize()
1529 DEVICE(balloon)); in hv_balloon_vmdev_realize()
1530 } else if (balloon->addr) { in hv_balloon_vmdev_realize()
1536 timer_init_ms(&balloon->post_init_timer, QEMU_CLOCK_VIRTUAL, in hv_balloon_vmdev_realize()
1537 hv_balloon_post_init_timer, balloon); in hv_balloon_vmdev_realize()
1539 qemu_register_reset(hv_balloon_system_reset, balloon); in hv_balloon_vmdev_realize()
1544 qemu_remove_balloon_handler(balloon); in hv_balloon_vmdev_realize()
1556 HvBalloon *balloon = HV_BALLOON(vdev); in hv_balloon_vmdev_reset() local
1558 if (balloon->state == S_POST_RESET_CLOSED) { in hv_balloon_vmdev_reset()
1562 if (balloon->our_range) { in hv_balloon_vmdev_reset()
1563 hvb_our_range_clear_removed_trees(OUR_RANGE(balloon->our_range)); in hv_balloon_vmdev_reset()
1566 hvb_page_range_tree_destroy(&balloon->removed_guest); in hv_balloon_vmdev_reset()
1567 hvb_page_range_tree_destroy(&balloon->removed_both); in hv_balloon_vmdev_reset()
1568 hvb_page_range_tree_init(&balloon->removed_guest); in hv_balloon_vmdev_reset()
1569 hvb_page_range_tree_init(&balloon->removed_both); in hv_balloon_vmdev_reset()
1571 balloon->trans_id = 0; in hv_balloon_vmdev_reset()
1572 balloon->removed_guest_ctr = 0; in hv_balloon_vmdev_reset()
1573 balloon->removed_both_ctr = 0; in hv_balloon_vmdev_reset()
1575 HV_BALLOON_SET_STATE(balloon, S_POST_RESET_CLOSED); in hv_balloon_vmdev_reset()
1576 hv_balloon_event_loop(balloon); in hv_balloon_vmdev_reset()
1584 static void hv_balloon_unrealize_finalize_common(HvBalloon *balloon) in hv_balloon_unrealize_finalize_common() argument
1586 hv_balloon_free_mr(balloon); in hv_balloon_unrealize_finalize_common()
1587 balloon->addr = 0; in hv_balloon_unrealize_finalize_common()
1589 balloon->memslot_count = 0; in hv_balloon_unrealize_finalize_common()
1594 HvBalloon *balloon = HV_BALLOON(vdev); in hv_balloon_vmdev_unrealize() local
1596 qemu_unregister_reset(hv_balloon_system_reset, balloon); in hv_balloon_vmdev_unrealize()
1598 hv_balloon_system_reset_unrealize_common(balloon); in hv_balloon_vmdev_unrealize()
1600 qemu_remove_balloon_handler(balloon); in hv_balloon_vmdev_unrealize()
1602 if (balloon->hostmem) { in hv_balloon_vmdev_unrealize()
1603 vmstate_unregister_ram(host_memory_backend_get_memory(balloon->hostmem), in hv_balloon_vmdev_unrealize()
1604 DEVICE(balloon)); in hv_balloon_vmdev_unrealize()
1605 host_memory_backend_set_mapped(balloon->hostmem, false); in hv_balloon_vmdev_unrealize()
1608 hvb_page_range_tree_destroy(&balloon->removed_guest); in hv_balloon_vmdev_unrealize()
1609 hvb_page_range_tree_destroy(&balloon->removed_both); in hv_balloon_vmdev_unrealize()
1611 hv_balloon_unrealize_finalize_common(balloon); in hv_balloon_vmdev_unrealize()
1629 HvBalloon *balloon = HV_BALLOON(md); in hv_balloon_md_get_memory_region() local
1631 if (!balloon->hostmem) { in hv_balloon_md_get_memory_region()
1635 hv_balloon_ensure_mr(balloon); in hv_balloon_md_get_memory_region()
1637 return balloon->mr; in hv_balloon_md_get_memory_region()
1663 const HvBalloon *balloon = HV_BALLOON(md); in hv_balloon_md_fill_device_info() local
1670 if (balloon->hostmem) { in hv_balloon_md_fill_device_info()
1671 hi->memdev = object_get_canonical_path(OBJECT(balloon->hostmem)); in hv_balloon_md_fill_device_info()
1672 hi->memaddr = balloon->addr; in hv_balloon_md_fill_device_info()
1674 hi->max_size = memory_region_size(balloon->mr); in hv_balloon_md_fill_device_info()
1687 HvBalloon *balloon = HV_BALLOON(md); in hv_balloon_decide_memslots() local
1692 assert(!balloon->memslot_count); in hv_balloon_decide_memslots()
1695 assert(balloon->hostmem); in hv_balloon_decide_memslots()
1697 hostmem_mr = host_memory_backend_get_memory(balloon->hostmem); in hv_balloon_decide_memslots()
1706 balloon->memslot_size = memslot_size; in hv_balloon_decide_memslots()
1708 balloon->memslot_size = region_size; in hv_balloon_decide_memslots()
1712 balloon->memslot_count = memslots; in hv_balloon_decide_memslots()
1717 const HvBalloon *balloon = HV_BALLOON(md); in hv_balloon_get_memslots() local
1720 assert(balloon->memslot_count > 0); in hv_balloon_get_memslots()
1722 return balloon->memslot_count; in hv_balloon_get_memslots()
1731 HvBalloon *balloon = HV_BALLOON(obj); in hv_balloon_finalize() local
1733 hv_balloon_unrealize_finalize_common(balloon); in hv_balloon_finalize()